Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #54930 > unrolled thread

Weird bahaviour from shlex - line no

Started byDaniel Stojanov <daniel.stjnv@gmail.com>
First post2013-09-28 16:26 +1000
Last post2013-09-28 16:26 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Weird bahaviour from shlex - line no Daniel Stojanov <daniel.stjnv@gmail.com> - 2013-09-28 16:26 +1000

#54930 — Weird bahaviour from shlex - line no

FromDaniel Stojanov <daniel.stjnv@gmail.com>
Date2013-09-28 16:26 +1000
SubjectWeird bahaviour from shlex - line no
Message-ID<mailman.404.1380351331.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web