How to use intern()? - newbie
Martin von Loewis
loewis at informatik.hu-berlin.de
Tue Jan 4 15:20:56 EST 2000
"Wm. King" <wjk at wjk.mv.com> writes:
> intern("ASTRING") -- puts that string internally in a table...
> 1. How do you access any string put away using intern().
The result of intern is the interned string:
>>> x = intern("Syntax"+"Error")
>>> x is SyntaxError.__name__
1
> 2. How would you put this function to good use / or what is
> its purpose.
The function is implicitly called in a lot of cases. Module, class,
and method names get interned, as well as identifier-like string
constants in source code. Interned strings are more efficient in
dictionary lookups, because it is only a pointer compare if they are
equal.
> 3. Python Quick Reference - says interned strings are "immortals".
> Does that mean for the duration of running program only?
Of course. Nothing lasts forever :)
Regards,
Martin
More information about the Python-list
mailing list