User Tools

Site Tools


python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
python [2012/07/30 02:46] memeruizpython [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("-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 ===== ===== How to make a python source code file executable =====
Line 19: Line 34:
   chmod +x example.py   chmod +x example.py
  
 +===== Important functions =====
 +
 +  os.walk("dir")
 +  os.*
 +  sys.argv
 +
 +===== Important modules =====
 +
 +  optparse
 +  multiprocessing
 +  numpy
  
python.1343616390.txt.gz · Last modified: 2021/02/01 05:55 (external edit)