How can you copy (clone) a string?

piet at cs.uu.nl piet at cs.uu.nl
Thu Oct 5 11:41:51 EDT 2000


>>>>> "Makhno" <mak at imakhno.freeserve.co.uk> (M) writes:

>> i = 0
>> s = 1000 * 'x'
>> mem = None
>> while 1:
>> i = i+1
>> mem = (mem, s+`i`)
>> 
>> might work (untested)

M> From the look of it, it will stop when approximately half the memory
M> resource is used up, as the string needs to be copied to be enlarged.

I think your look is incorrect as I don't copy a growing string, all my
strings are approximately 1000 characters. The tuples are constant in size,
I just get more and more of them. Each just has a pointer to the previous
one and to a new string.
-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.van.Oostrum at hccnet.nl



More information about the Python-list mailing list