Tricks to do "enums"?
emile at fenx.com
emile at fenx.com
Mon May 8 10:27:36 EDT 2000
Watch out for this one. IRK, this results from auto interning some
strings.
>>> a = "this is a longer string value"
>>> eval("'this is a longer string value' is a")
0
>>> b = "JoeJoeJoeJoeJoeJoeJoeJoeJoeJoeJoeJoeJoe"
>>> eval ("'JoeJoeJoeJoeJoeJoeJoeJoeJoeJoeJoeJoeJoe' is b")
1
There's-an-assumption-at-the-bottom-of-this-I-assume-ly y'rs,
Emily van Sebille
emile at fenx.com
Neil Schemenauer <nascheme at enme.ucalgary.ca> wrote in message
news:<slrn8hcuf4.bh.nascheme at cranky.arctrix.com>...
> 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
> --
> http://www.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list