Python name lookups / Interning strings

"Martin v. Löwis" martin at v.loewis.de
Tue Oct 11 20:30:47 EDT 2005


Dave wrote:
> What exactly does it mean to "intern" a string?

"exactly" it means to place lookup the string in the
global interning dictionary. If an entry is found,
then interning yields the string in the interning dictionary.
If the string is not found, it is added to the interning
dictionary, and returned; its "interning state" is set
to "interned" (either mortally or immortally, depending
on the exact interning request).

More colloquially, it means to find a unique representative
of the set of all equal-valued strings (e.g. one unique
representative for all strings equalling "close"). If
a and b are variables referring to interned strings,
'a==b' implies 'a is b' (whereas usually only the
reverse is true).

HTH,
Martin



More information about the Python-list mailing list