i come back to python; just some questions

Duncan Booth duncan at NOSPAMrcp.co.uk
Mon Jul 15 04:34:03 EDT 2002


ppcdev at hotmail.com (ppcdev) wrote in 
news:2fa5f3a9.0207140808.e4d7d38 at posting.google.com:

> i was working on an old pentium II and wanted to send a very long
> string in the USER parameter but it made my computer bug.. is it
> normal???
> 
> str='a'; r=range(1024);
> for x in r[:]:
>     str=str+str
> 
> but it even bugs with a value of 512 and 256 for r=range(..)

You are doubling the length of the string each time, so with a range of 
1024 you are attempting to create a string that is 
179769313486231590772930519078902473361797697894230657273430081157732675805
500963132708477322407536021120113879871393357658789768814416622492847430639
474124377767893424865485276302219601246094119453082952085005768838150682342
462881473913110540827237163350510684586298239947245938479716304835356329624
224137216 characters long.

Are you sure you have that much memory available?

To get a not so long string, just try something like:
  myString = 'a' * 1024

N.B. It isn't a good idea to call a variable 'str' as you will be hiding 
the builtin type 'str' which you might also want to use.
N.N.B. There wasn't any need to copy the range 'r[:]' before using it in 
the for loop.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list