469,270 Members | 1,026 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

optparse commandline


I want to call some function from my program and just pass it a
commandline. It should parse the commandline and return back a list of
parsed arguments (just like the sys.argv list)

Example:
foo.parse_cmdline("/usr/bin/foorun -v -d -h")
==['/usr/bin/foorun', '-v', '-d','-h']

Any suggestions on how to do this are appreciated.

Regards
Vikram

Jul 8 '07 #1
1 1058
On Sun, 08 Jul 2007 09:59:29 +0000, vvikram wrote:
>
I want to call some function from my program and just pass it a
commandline. It should parse the commandline and return back a list of
parsed arguments (just like the sys.argv list)

Example:
foo.parse_cmdline("/usr/bin/foorun -v -d -h")
==['/usr/bin/foorun', '-v', '-d','-h']

Any suggestions on how to do this are appreciated.
def parse_cmdline(s):
"""Split a command line string s into words."""
import shlex
return shlex.split(s)


--
Steven.

Jul 8 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Hans-Joachim Widmaier | last post: by
1 post views Thread by Eric O. Angell | last post: by
7 posts views Thread by Henry Ludemann | last post: by
3 posts views Thread by Karlo Lozovina | last post: by
4 posts views Thread by Mathias Waack | last post: by
1 post views Thread by Jeff Keasler | last post: by
reply views Thread by Robert Kern | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.