On Nov 9, 8:34 pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Sun, 09 Nov 2008 23:33:30 +0100, Thomas Mlynarczyk
> <[EMAIL PROTECTED]> declaimed the following in
> comp.lang.python:
>
>
>
> > Of course. For the actual message I would use at least the line number.
> > Still, the offset could be used to compute line/column in case of an
> > error, so I wouldn't really need to store line/column with each token,
> > but only the offset. And provide a method to "convert" offset values
> > into line/column tuples.
>
>         Are you forcing the use of fixed length lines then?
>
>         Otherwise, by what algorithm will you convert:
>
> >>> data = """
>
> ... one
> ... two
> ... three
> ... four
> ... five
> ... supercalifragilisticexpialidocious
> ... seven
> ... eight
> ... nine""">>> ix = data.index("list")
> >>> ix
> 39

loc = data.index("list")
print data[:loc].count("\n")-1
print loc-data[:loc].rindex("\n")-1

prints 5,14

I'm sure it's non-optimal, but it *is* an algorithm that does not
require keeping track of the start of every line...

-- Paul
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to