[Python Wpg] Minor headache with substrings

Stuart Williams stuartw at mts.net
Fri Feb 22 19:58:37 EST 2008


You wrote original_string[start:length], that should be
original_string[start:stop].  Does that indicate a misunderstanding
about strings that could explain the behaviour your seeing?

If you send sample code I could investigate further.

Stuart.

On Fri, Feb 22, 2008 at 5:53 PM, Mike Pfaiffer <high.res.mike at gmail.com> wrote:
>         First off this is a precursor to my first adventure with GUI
>  programming. I figured I'd write something which works first and then
>  add a GUI to it.
>
>         I want to split a rather large string (< 2,000,000 characters) at
>  random locations. The resulting substrings get sent out to a file for
>  later reassembly. At this point it is only coincidental the substrings
>  are sequential to each other. I've been using
>  "original_string[start:length]" to copy the data to a second string
>  which goes to the output file. I'm able to calculate the start for the
>  subsequent substrings correctly. However when putting the substring in a
>  second variable I occasionally get a length of 1 (which should never
>  occur). Seeing this problem on the screen, I now think I'm missing
>  something. I think it could be in one of three areas. Either it's
>  something about the nature of strings in Python. Maybe I should be using
>  a different procedure to take out substrings. Or there is a problem with
>  the size of "start" or "length". So I suppose my question is am I on the
>  right track with this?
>
>                                 Later
>                                 Mike
>
>  _______________________________________________
>  Winnipeg mailing list
>  Winnipeg at python.org
>  http://mail.python.org/mailman/listinfo/winnipeg
>



More information about the Winnipeg mailing list