Weird bahaviour from shlex - line no

Daniel Stojanov daniel.stjnv at gmail.com
Sat Sep 28 02:26:24 EDT 2013


Can somebody explain this. The line number reported by shlex depends
on the previous token. I want to be able to tell if I have just popped
the last token on a line.




import shlex

first = shlex.shlex("word1 word2\nword3")
print first.get_token()
print first.get_token()
print "line no", first.lineno, "\n"

second = shlex.shlex("word1 word2,\nword3")
print second.get_token()
print second.get_token()
print second.get_token()
print "line no", second.lineno, "\n"


OUTPUT:
word1
word2
line no 2

word1
word2
,
line no 1



More information about the Python-list mailing list