[Tutor] Tab delimited question

Alan Gauld alan.gauld at btinternet.com
Mon Dec 13 21:17:17 CET 2010


"Ben Ganzfried" <ben.ganzfried at gmail.com> wrote
> def test(infile, outfile):
>  for line in infile:
>            tagIndex = line.find("key")
>            start = tagIndex + 4
>            stop = line[start:].find("\t") -1
>            if tagIndex != -1:
>                print("start is: ", start)
>                print("stop is: ", stop)
>                print("spliced word is ", line[start: stop])
>
> My question is the following: What is wrong w/ the variable 'stop'?
> The index it gives me when I print out 'stop' is not even close to 
> the
> right number.

Some clues would be good - like the programs output?
And its hard to tell where the \t characters are in an email,
so knowing what find is looking at would help too.

> Furthermore, when I try to print out just the word
> following the tag w/ the form: line[start: stop], it prints nothing
> (it seems b/c my stop variable is incorrect).

If stop is wrong that seems likely. Is it possible there is a tab in
there that you didn't expect? Have you tried printing all the
character codes of all whitespace? Or replacing all tabs
with 'TAB' say?


HTH,





More information about the Tutor mailing list