# get command line args into a dictionary for parsing # get a name list file into a dictionary for look up d = { "a":"alpha", "g":"gamma", "d":"delta", 7:11.25} print d print type(d) print len(d) print d.keys() # key:value pairs, also known as mapping; can be different data types # dictionaries are unordered so numerical indexing does not work # appear to be internally sorted alphabetically # dictionary is indexed by key instead of a numerical index for j in d: # magic iterator return elements from list of keys print j print " the key is a " + str(type(j)) v = d.get(j) # python magic: v = d[j]; index by key instead of number print v print " the value is a " + str(type(v)) import sys # import can be anywhere in code, usually at beginning print sys.argv # sys.argv is a list of command line arguments starting with programName # command line usage: python program.py -d directory -f nFrames -o outputfile # arguments can be in any order and optional eD = {} # lists, tuples, dictionaries have to be declared, unlike int, float # convention is add letter for datatype at end of variable name for j in range(1, len(sys.argv), 2): # range can have a skip factor print sys.argv[j], sys.argv[j+1] eD[sys.argv[j]] = sys.argv[j+1] print eD print "the output file will be " + eD["-o"] print "the number of frames will be " + eD["-f"] ''' a = 1 b = 2 print a; print b # ; generally not used; can separate 2 statements on same line e = {} print e print type(e) e['hello'] = "goodbye" print e '''