shlex last token

Peter Maas fpetermaas at netscape.net
Fri Jun 13 07:36:22 EDT 2003


I am trying to use shlex.shlex and I don't no how to tell that the
input stream is at EOF (other than using exceptions).

### My code:

import shlex
inp = file("someTextFile")
sc = shlex.shlex()
sc.push_source(inp)

while sc.state:
     print sc.get_token()

sc.state doesn't change when there is no token left nor does sc.token.
I also tried inp.tell() and inp.closed, but it seems that the
get_token() method raises a ValueError exception instead of setting
a flag if it hits the end of the input stream. I can bracket the
while loop with try..except but I find that ugly. Does somebody know
a better way?

Mit freundlichen Gruessen,

Peter Maas

-- 
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail peter.maas at mplusr.de
-------------------------------------------------------------------






More information about the Python-list mailing list