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. Advertising

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. Replies:
    4
    Views:
    1,236
  2. r0g
    Replies:
    3
    Views:
    452
  3. Andreas Perstinger

    Re: Weird bahaviour from shlex - line no

    Andreas Perstinger, Sep 28, 2013, in forum: Python
    Replies:
    0
    Views:
    118
    Andreas Perstinger
    Sep 28, 2013
  4. Dave Angel
    Replies:
    0
    Views:
    125
    Dave Angel
    Sep 28, 2013
  5. Peter Otten
    Replies:
    1
    Views:
    126
    Piet van Oostrum
    Sep 28, 2013
Loading...

Share This Page