Tricks to do "enums"?

Neil Schemenauer nascheme at enme.ucalgary.ca
Mon May 8 10:07:53 CEST 2000


Courageous <jkraska1 at san.rr.com> wrote:
>So, it would appear that the limit would be uneval'd
>strings, potentially taken from the user or a file.

Yes:

    >>> a = "a"
    >>> b = raw_input()
    a
    >>> a is b
    0
    >>> a == b
    1
    >>> b = intern(b)
    >>> a is b
    1

Trying to figure out when Python shares immutable objects can be
a lot of fun:

    >>> a = 1
    >>> b = 1
    >>> a is b
    1
    >>> a = 1000
    >>> b = 1000
    >>> a is b
    0
    >>> 1000 is 1000
    1


>This isn't something c or c++ can do for you, either.

No.  I think the idea comes from Lisp.  I don't think Guido is a
big Lisp user so the idea may have come from somewhere else.
Lisp has a function called intern though so the connection seems
pretty strong.

    Neil

-- 
The short in SHARE_SHORTS_STRINGS is pretty short otherwise
things would be even more fun.



More information about the Python-list mailing list