472,145 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

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 1088
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
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.