Perl to Python: Modules & Extensions
Modules
Import a module's functions into their own namespace:
import module => module.foobar()
Import certain functions into the main namespace
from module import foobar => foobar()
Import all functions of a module into the main namespace:
from module import * => foobar()
Which modules are loaded: dir()
Which names does a module provide: dir(modulename)
sys
sys.argv() => command-line arguments as list
sys.stderr.write(“panic!“) => print to STDERR
sys.exit() => quit the program
os
dir(os) => which methods are there?
help(os) => manual page
os.system(“/bin/date“)
os.getcwd()
os.chdir(“/tmp“)
shutil
shutil.copyfile(from, to)
shutil.move(from, to)
glob
glob.glob(“*.txt“) => ['README.txt', 'LICENSE.txt']
getopt
try:
opts, args = getopt.getopt(sys.argv[1:], 'xc:', ['extended', 'config=', ])
except getopt.GetoptError, e:
sys.stderr.write("Error reading arguments: %s\n" % e)
usage(1)
for (key, val) in opts:
if key == '--help': ...
