How do I get a slice of a string held in a tuple?
aleax at mac.com
Mon Apr 9 04:14:11 CEST 2007
Lorenzo <lorenzo at excitement.com> wrote:
> > > elapsedTime = mydata
> > > 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.find("real")
> elapsedTime = mydata[index:]
The only difference is that in the "workaround that works" you're
mungling mydata, in the "bad code" mydata. 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