[Python-Dev] Alternative implementation of interning, take 2
Guido van Rossum
guido@python.org
Fri, 12 Jul 2002 08:52:01 -0400
> What I do need and rely on is the fact that the
> Python compiler interns all constant strings and identifiers in
> Python programs. This makes switching like so:
>
> if a == 'x':
> elif a == 'y':
> else:
>
> also work like this (only faster):
>
> if a is 'x':
> elif a is 'y':
> else:
>
> provided that 'a' only uses interned strings.
Yuck. This is an implementation detail. While it's unlikely to go
away in Python 2.0, please don't rely on this in portable Python.
--Guido van Rossum (home page: http://www.python.org/~guido/)