How can you copy (clone) a string?
Mark Jackson
mjackson at wc.eso.mc.xerox.com
Tue Oct 3 10:52:30 EDT 2000
=?ISO-8859-1?Q?Max_M=F8ller_Rasmussen?= <maxm at normik.dk> writes:
> Just use slice:
>
> a = 'a'
> b = a[:]
Doesn't work, at least in 1.5.2:
>>> a = 'a'
>>> b = a[:]
>>> a is b
1
The following perversity seems to do the trick unless a = '':
>>> c = repr(a)[1:-1]
>>> a is c
0
But I am inclined to agree with the eff-bot: If you think you need to
do this, it's time to redesign your program.
--
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
I respect faith, but doubt is what gets you an education.
- Wilson Mizner
More information about the Python-list
mailing list