Page History
Content
Table of Contents |
---|
Parsing of input parameters
Parsing "on knees"
Code Block |
---|
import sys
import os
def get_input_parameters() :
nargs = len(sys.argv)
print 'sys.argv[0]: ', sys.argv[0]
print 'nargs: ', nargs
# Then do something with arguments...
|
Use OptionParser
Code Block |
---|
from optparse import OptionParser
def input_option_parser() :
def_fname = 'spec-xppi0412-r0060-20120507-125420.198726277.txt'
def_cols = 100
parser = OptionParser(description='Process optional input parameters.', usage = "usage: %prog [options]")
parser.add_option('-f', '--fname', dest='fname', default=def_fname, action='store', type='string', help='input file name')
parser.add_option('-c', '--cols', dest='cols', default=def_cols, action='store', type='int', help='number of columns in the image array')
parser.add_option('-v', dest='verbose', action='store_true', help='set flag to print more details', default=True)
parser.add_option('-q', dest='verbose', action='store_false', help='set flag to print less details')
(opts, args) = parser.parse_args()
print 'opts:',opts
print 'args:',args
return (opts, args)
|
Manipulation with directories and files
Access to files in the derectory
Code Block |
---|
def getListOfFilesInDir(dirname) :
return os.listdir(dirname)
def printListOfFilesInDir(dirname) :
print 'List of files in the dir.', dirname
for name in os.listdir(dirname) :
print name
print '\n'
|
Parsing the pathname
Code Block |
---|
name, ext = os.path.splitext(fname)
basename = os.path.basename(path)
dirname = os.path.dirname(path)
lexist = os.path.lexists(path)
...
|
http://docs.python.org/library/os.path.html
Matplotlib
In examples below we assume
...
Overview
Content Tools