Tricks to do "enums"?
Michael Hudson
mwh21 at cam.ac.uk
Mon May 8 10:53:45 EDT 2000
emile at fenx.com writes:
> 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,
Look at Python/compile.c, line 261 (or search for "Intern selected
string constants"). Basically string constants that *could* be Python
identifiers (ie. consist entirely of A-Za-z0-9_) are interned.
I think this is the third (or fourth?) time I have posted this bit of
information to this newsgroup...
Cheers,
Michael
--
81. In computing, turning the obvious into the useful is a living
definition of the word "frustration".
-- Alan Perlis, http://www.cs.yale.edu/~perlis-alan/quotes.html
More information about the Python-list
mailing list