Tab expansion problem or ..?
Tony C
cappy2112 at yahoo.com
Sat Feb 28 14:43:43 EST 2004
> >
> > for line in fhIn:
> > if 'HEXNUM' in line.expandtabs():
> > Hexloc = line.find('HEXNUM')
> > print"\n%s" % line[:Hexloc]
> >
>
> You are throwing away the result of line.expandtabs() in the above code.
> Therefore the expansion effects neither the printed line nor the Hexloc
> index. It should rather be (untested)
>
> for line in fhIn:
> if "HEXNUM" in line:
> line = line.expandtabs()
> Hexloc = line.find("HEXNUM")
> print "\n%s" % line[:Hexloc]
>
In my *actual* code, I am storing the result from expandtabs()
I was away from the computer where my sources were, so I just typed in
a quick
example- but overlooked storeing the result from expantabs().
That being said, I still don't understand why the index returned from
find()does not give me the correct offset into the string, where the
label HeXNUM is.
More information about the Python-list
mailing list