Skip to content

Instantly share code, notes, and snippets.

@nitinsatish
Created January 14, 2012 16:19
Show Gist options
  • Save nitinsatish/1611928 to your computer and use it in GitHub Desktop.
Save nitinsatish/1611928 to your computer and use it in GitHub Desktop.
python argument parser
#!/usr/bin/python
import sys
def getopt(args):
if len(args)>1:
opts={}
while (args):
if args[0][0]=='-':
opts[args[0]]=args[1]
args=args[2:]
else:
args=args[1:]
return opts
if __name__=='__main__':
options=getopt(sys.argv[1:])
if options:
print options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment