Tricks to do "enums"?

Neil Schemenauer nascheme at enme.ucalgary.ca
Mon May 8 03:22:59 EDT 2000


Courageous <jkraska1 at san.rr.com> wrote:
>Do all string constants which are lexically equivalent obey
>the identity rule? IOW, does the python byte compiler know
>how, upon compilation, to make two seperate instance of
>"joe" point to the same single instance?

A very good question.  I believe that the magic happens when code
objects are created.  Importing a module causes code objects to
be created from marshalled code objects.  String constants are
interned during the creation of new code objects.

>If so, what are the limits of the byte compiler at merging
>string identities? For example, will eval() do a prepass
>through the code and determine identity?

If my hypothese above is correct then it should work:

    >>> a = "a"
    >>> eval("'a' is a")
    1

Mmm, support.  Pretending to be a guru is hard work. :)

    Neil

-- 
"God, root, what is difference?" - Pitr
"God is more forgiving." - Dave Aronson



More information about the Python-list mailing list