Next / Previous / Contents / Shipman's homepage

6.7. line(): In what line does a location occur?

pp.line(loc, text)

Given a string text and a location loc (Python index) within that string, this function returns the line containing that location, without a line terminator.

>>> text = 'abc\nde\nf\n'
>>> for loc in range(len(text)):
...     print "{0:2d} '{1}'".format(loc, pp.line(loc, text))
... 
 0 'abc'
 1 'abc'
 2 'abc'
 3 'abc'
 4 'de'
 5 'de'
 6 'de'
 7 'f'
 8 'f'