Disable automatic interning

Hrvoje Niksic hniksic at xemacs.org
Mon Mar 23 13:54:56 EDT 2009


George Sakkis <george.sakkis at gmail.com> writes:

> I'm working on some graph generation problem where the node identity
> is significant (e.g. "if node1 is node2: # do something) but ideally I
> wouldn't want to impose any constraint on what a node is

I'm not sure if it helps in your case, but you can easily turn off the
optimization by subclassing from the string type:

>>> class mystr(str):
...   pass
...
>>> s = mystr('x')
>>> s
'x'
>>> s is 'x'
False

Since mystr can have additional functionality on top of str, the
caching doesn't apply to the subclass instances.



More information about the Python-list mailing list