python
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| python [2012/07/30 02:44] – created memeruiz | python [2021/02/01 05:55] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| ===== How to read command line arguments ===== | ===== How to read command line arguments ===== | ||
| + | |||
| + | ==== Simple approach ==== | ||
| + | |||
| import sys | import sys | ||
| print sys.argv # this is an array containing all command line arguments inclusive the program name | 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(" | ||
| + | help=" | ||
| + | parser.add_option(" | ||
| + | action=" | ||
| + | help=" | ||
| + | (options, args) = parser.parse_args() | ||
| + | |||
| + | ===== How to make a python source code file executable ===== | ||
| + | |||
| + | Code example: | ||
| + | |||
| + | # | ||
| + | print " | ||
| + | |||
| + | In the console don't forget to give executable permissions: | ||
| + | |||
| + | chmod +x example.py | ||
| + | |||
| + | ===== Important functions ===== | ||
| + | |||
| + | os.walk(" | ||
| + | os.* | ||
| + | sys.argv | ||
| + | |||
| + | ===== Important modules ===== | ||
| + | |||
| + | optparse | ||
| + | multiprocessing | ||
| + | numpy | ||
python.1343616262.txt.gz · Last modified: 2021/02/01 05:55 (external edit)
