How can you copy (clone) a string?
Johann Hibschman
johann at physics.berkeley.edu
Tue Oct 3 16:16:30 EDT 2000
Bernhard Herzog writes:
> a possible solution for the problem if the string is at least two
> characters long:
>>>> t = s[:1] + s[1:]
>>>> s is t
> 0
There's always the straightforward
>>> import array
>>> str = "Hi, mom!"
>>> a = array.array('c', str)
>>> str2 = a.tostring()
>>> str2
'Hi, mom!"
>>> str2 is str
0
The array module does many magical things. ;-)
--
Johann Hibschman johann at physics.berkeley.edu
More information about the Python-list
mailing list