Comment

Comment by marmaduke

  Enumerations support iteration, in definition order:
  
  >>> class Shake(Enum):
  ...   vanilla = 7
  ...   chocolate = 4
  ...   cookies = 9
  ...   mint = 3
  ...
  >>> for shake in Shake:
  ...   print(shake)
  ...
  Shake.vanilla
  Shake.chocolate
  Shake.cookies
  Shake.mint
Python's execution model sez that the class declaration is nothing more than code that is exec'd in a dictionary. We know that Python dictionaries do not perserve order, so why is this iteration in definition order possible, barring modification to the interpreter or dict type ?
parent marmaduke 13 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton