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


Groups > comp.lang.python > #54930

Weird bahaviour from shlex - line no

Date 2013-09-28 16:26 +1000
Subject Weird bahaviour from shlex - line no
From Daniel Stojanov <daniel.stjnv@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.404.1380351331.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web