<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
> Thanks for the info on xrange. Writing single char is just to get going
> quickly. I knew that I would have to improve on that. I would like to
> write chunks of 1MB which would require that I have 1MB string to
> write. Is there any simple way of generating this 1MB string

megastring = 1000000*'a' # t < 1 sec on my machine

>(other than keep appending to a string until it reaches 1MB len)?

You mean like (unexecuted)
s = ''
for i in xrange(1000000): s += 'a' #?

This will allocate, copy, and  deallocate 1000000 successively longer 
temporary strings and is a noticeable O(n**2) operation.  Since strings are 
immutable, you cannot 'append' to them the way you can to lists.

Terry J. Reedy



-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to