User Tools

Site Tools


python

Python

Important things to know in python:

How to read command line arguments

Simple approach

import sys
print sys.argv # this is an array containing all command line arguments inclusive the program name

OptParse

from optparse import OptionParser
parser = OptionParser()
parser.add_option("-f", "--file", dest="filename",
                  help="write report to FILE", metavar="FILE")
parser.add_option("-q", "--quiet",
                  action="store_false", dest="verbose", default=True,
                  help="don't print status messages to stdout")
(options, args) = parser.parse_args()

How to make a python source code file executable

Code example:

#!/usr/bin/env python # this finds the default python executable defined by the current environment (PATH).
print "test"

In the console don't forget to give executable permissions:

chmod +x example.py

Important functions

os.walk("dir")
os.*
sys.argv

Important modules

optparse
multiprocessing
numpy
python.txt · Last modified: 2012/07/29 22:54 by memeruiz