Tricks to do "enums"?

emile at fenx.com emile at fenx.com
Mon May 8 17:38:42 CEST 2000


Ah... but this is only the first time I got it.  Thanks.

The-third-(or-fourth?)-time's-a-charm-ly y'rs,

Emile van Sebille
emile at fenx.com

Michael Hudson <mwh21 at cam.ac.uk> wrote in message
news:<m3g0rtt7nq.fsf at atrus.jesus.cam.ac.uk>...
> 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
> -- 
> http://www.python.org/mailman/listinfo/python-list
>




More information about the Python-list mailing list