How do I get a slice of a string held in a tuple?

Alex Martelli aleax at
Mon Apr 9 04:14:11 CEST 2007

Lorenzo <lorenzo at> wrote:
> > >  elapsedTime = mydata[1]
> > >  index = elapsedTime.find("real")
> > >  # the index will have a value 0f 110
> > >  totaltime = elapsedTime[index:]
> Oops! I sent the wrong piece of code. The above is actually the work 
> around which actually works. The bad code is this:
> index  = mydata[0].find("real")
> elapsedTime = mydata[0][index:]

The only difference is that in the "workaround that works" you're
mungling mydata[1], in the "bad code" mydata[0].  If you print or
otherwise emit the value of index in each case, I think the cause of
your problem will become clear (and it will probably be a value of index
that's -1 for the "failing" case, and >= 0 for the "working" case, as
other posts on this thread have already suggested).

No connection can exist between your problem, and the string being "held
in a tuple" or held in any other fashion.


More information about the Python-list mailing list