intern'ed strings and deepcopy()

Alexander Schmolck a.schmolck at gmx.net
Fri Apr 11 19:40:09 EDT 2003


Erik Max Francis <max at alcyone.com> writes:

> Fortepianissimo wrote:
> 
> > I can't seem to find the exact description between these two in the
> > Library Reference - so am I correct in assuming that deepcopy() will
> > not actually duplicate an intern'ed string?
> 
> Strings are immutable, so what good would a copy (via copy or deepcopy)
> do you?  You cannot possibly change an existing string object, so its
> identity is unimportant.

No it isn't. The idea of symbols (viz interned strings) is their uniqueness
(amongst other things, establishing identity is faster then establishing
string equality). So I don't think the OP's question is unreasonable: you
might well want to deepcopy some container that contains symbols (and you'd
like to preserve their identity).

I'm pretty sure that deepcopy will not duplicate objects it knows to be
immutable, but explicitly documenting this behavior (even as undefined) might
be useful.

'as




More information about the Python-list mailing list