# python scripts are often run from the # command line. # python can retrieve and use command line # arguments with the sys module. import sys # all arguments are stored in the sys.argv list print "number of arguments passed: ", len(sys.argv) # process through the argument list for argument in sys.argv: print argument # my input/output: # python commandlinearguments.py one two three four five six seven # number of arguments passed: 8 # commandlinearguments.py # one # two # three # four # five # six # seven
A python example based blog that shows how to accomplish python goals and how to correct python errors.
Thursday, November 19, 2009
Python - processing command line arguments
Wednesday, November 18, 2009
Python - boolean and, or, and not
# python includes the basic and, # or, and not boolean operations a = 10 b = 20 c = 30 if a>9 and b+1==21 and c==a+b: print "boolean 'and' example equates true" if a==9 or b<10 or c<100: print "only one of these expressions needs to be true" if not a+b==31: print "if this is not true"
Subscribe to:
Posts (Atom)