Weird bahaviour from shlex - line no

Discussion in 'Python' started by Daniel Stojanov, Sep 28, 2013.

  1. 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
     
    Daniel Stojanov, Sep 28, 2013
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bill

    incorrect(?) shlex behaviour

    bill, May 14, 2005, in forum: Python
    Replies:
    4
    Views:
    520
    Donn Cave
    May 16, 2005
  2. Replies:
    4
    Views:
    1,320
  3. Bug in shlex??

    , Apr 3, 2008, in forum: Python
    Replies:
    2
    Views:
    392
  4. Replies:
    1
    Views:
    490
    Nobody
    Aug 30, 2010
  5. r0g
    Replies:
    3
    Views:
    614
  6. Karim

    shlex parsing

    Karim, Jul 27, 2011, in forum: Python
    Replies:
    10
    Views:
    1,322
    Karim
    Jul 29, 2011
  7. Timo Hoepfner

    Strange bahaviour of "Set"

    Timo Hoepfner, Dec 12, 2005, in forum: Ruby
    Replies:
    0
    Views:
    141
    Timo Hoepfner
    Dec 12, 2005
  8. Peter Otten
    Replies:
    1
    Views:
    192
    Piet van Oostrum
    Sep 28, 2013
Loading...