Collect command-line options in a dictionary,,def getopts(
Collect command-line options in a dictionary,,def getopts(
def getopts(argv): opts = {} while argv: if argv[0][0] == '-': # find '-name value' pairs opts[argv[0]] = argv[1] # dict key is '-name' arg argv = argv[2:] else: argv = argv[1:] return optsif __name__ == '__main__': from sys import argv myargs = getopts(argv) if myargs.has_key('-i'): print myargs['-i'] print myargs
- A trailing comma avoids the newline after the output,,
- dir() does not list the names of built-in functions and
- Russian encode,russianencode,title = u'\u
- Random integers produced by randrange.,integersrandran
- Python object persistence for dictionary like object,p
- Defining Clean-up Actions,definingclean-up,try: ra
热门文章:
相关内容
- A trailing comma avoids the newline after the output,,a, b = 0, 1w
- dir() does not list the names of built-in functions and variables,b
- Russian encode,russianencode,title = u'\u
- Random integers produced by randrange.,integersrandrange,import ran
- Python object persistence for dictionary like object,pythonpersiste
- Defining Clean-up Actions,definingclean-up,try: rai
- Concatinate two tuples,concatinatetuples,inventory =
- Check if a default parameter value being used,checkparameter,def sa
- range and tuple,rangetuple,red, green,
- print variable into a string,printvariable,x = 42y = 3.
评论关闭