Should enum values be class instances? Or is this inefficient?

Tom nospam at nospam.com
Tue Aug 29 23:14:44 EDT 2000


I came across an implementation of enumerations (at
http://wwwhome.cs.utwente.nl/~gansevle/python/Enum.py) in which values of
the enum type are instances of the enum class.

Will this consume huge amounts of memory (one instance of the enum class for
every enum variable) or will the interpreter only create as many instances
as there are unique values of the enumeration?

So, I want to have value in my class that refers to an enumeration which has
6 unique enumerators.  My program might create 1000 instances of this class.
So each of the 1000 instances of my class will have a reference to an
instance of the enumeration class.  (That's 1000 references, but I assume
that references don't take too much memory.)   Will Python create 6
instances of the enumeration class, or 1000?

Instances are mutable aren't they?  And Python only invokes this efficiency
for immutables doesn't it?

Thanks for your comments,

Tom.








More information about the Python-list mailing list