[Python-Dev] shellwords

Gustavo Niemeyer niemeyer@conectiva.com
Wed, 16 Apr 2003 12:29:44 -0300


> Can shlex not be convinced to do what you want?  (Yes, I saw your Q/A, but
> didn't quite understand it.)

Oh, sorry. Just now I noticed that you didn't *understand* it.

He was talking about that:

>>> s = StringIO.StringIO("foo 'bar'asd'foo'")
>>> l = shlex.shlex(s)
>>> l.
l.__class__     l.error_leader  l.pop_source    l.source
l.__doc__       l.filestack     l.push_source   l.sourcehook
l.__init__      l.get_token     l.push_token    l.state
l.__module__    l.infile        l.pushback      l.token
l.commenters    l.instream      l.quotes        l.whitespace
l.debug         l.lineno        l.read_token    l.wordchars
>>> l.read_token()
'foo'
>>> l.read_token()
"'bar'"
>>> l.read_token()
"asd'foo'"
>>> 


In constrast to:

>>> shellwords.shellwords("foo 'bar'asd'foo'")
['foo', 'barasdfoo']

And also:

[niemeyer@localhost ~/src]% echo foo 'bar'asd'foo' 
foo barasdfoo

-- 
Gustavo Niemeyer

[ 2AAC 7928 0FBF 0299 5EB5  60E2 2253 B29A 6664 3A0C ]