intern'ed strings and deepcopy()

Alexander Schmolck a.schmolck at gmx.net
Sun Apr 13 13:01:38 EDT 2003


martin at v.loewis.de (Martin v. Löwis) writes:

> If you meant that 
> 
> type(a) == type(b) == str and b == a 'implies' intern(b) is intern(a)
> 
> then yes: Python does guarantee that, for arbitrary a,b.

Yes, this is of course what I meant (I apparently got tripped over a bit in
the process of translating my mentalese into python :)

> 
> Notice that Python does *not* (anymore) guarantee
> 
> type(a) == type(b) == str and b == a 'implies' id(intern(b)) == id(intern(a))

Huh? Really?

I thought  ``id(EXP1) == id(EXP2)`` implies ``EXP1 is EXP2`` and that's the
only difference I can see between the two lines.

So does this no longer hold true in python 2.3: "The `is' operator compares
the identity of two objects; the id() function returns an integer representing
its identity"? (the 2.3a2 reference openly admits its own inaccuracy in
general, but doesn't really seem to shed further light on this issue in particular).

> The intention is that intern gives you a unique distinct
> representative from the set of equal strings.

Yep, that's what I thought it would be :)

'as




More information about the Python-list mailing list