Perl to Python: Modules & Extensions

Modules

Import a module's functions into their own namespace:

Import certain functions into the main namespace

Import all functions of a module into the main namespace:

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': ...

WorkaroundOrg: PerlToPython/Modules (last edited 2005-08-29 18:40:51 by ChristophHaas)