copying a string???

Aahz aahz at
Thu Aug 22 10:57:09 EDT 2002

In article <3D64B97B.3BFDC676 at>,
Joe Connellan  <joec at> wrote:
>I have a function that alters the value of a string (written in C). (is
>that bad?)

Yes.  (Just to hammer the point in.)

>anyone know how I can really copy the string? or am I missing something

If you absolutely, positively, need a copy of a string, do this:

s2 = s1[:1] + s1[1:]

However, I should add the caveat that nothing in Python's language spec
guarantees that this will return a copy; it's simply deeply embedded in
the current implementation.
Aahz (aahz at           <*>

Project Vote Smart:

More information about the Python-list mailing list