Disable automatic interning

Daniel Fetchinson fetchinson at googlemail.com
Wed Mar 18 21:06:08 CET 2009

>> > Is there a way to turn off (either globally or explicitly per
>> > instance) the automatic interning optimization that happens for small
>> > integers and strings (and perhaps other types) ? I tried several
>> > workarounds but nothing worked:
>> No.  It's an implementation detail.
>> What use case do you have for wanting to disable it?
> 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.e. require
> a base Node class). It's not a show stopper, but it would be
> problematic if something broke when nodes happen to be (small)
> integers or strings.

But if two different nodes are both identified by, let's say the
string 'x' then you surely consider this an error anyway, don't you?
What's the point of identifying two different nodes by the same
string? If you use different strings (or numbers, even small ones) for
different nodes the whole problem will not arise.


Psss, psss, put it down! - http://www.cafepress.com/putitdown

More information about the Python-list mailing list