Size: 1241
Comment:
|
Size: 1754
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 14: | Line 14: |
The module os creates a portable abstraction layer which is used by high-level modules, like glob, socket, thred, time, fcntl. | The module os creates a portable abstraction layer which is used by high-level modules like glob, socket, thred, time, fcntl. |
Line 38: | Line 38: |
The module [[http://docs.python.org/lib/module-os.html|os]] is a portable operating system interface. |
|
Line 39: | Line 41: |
Some examples: * {{{os.system()}}} Executes the command (a string) in a subshell * {{{os.mkdir()}}} Creates a directory * {{{os.remove()}}} Deletes a file * {{{os.path.isdir()}}} Test if directory * {{{os.path.isfile()}}} Test if file * {{{os.path.exists()}}} Test if file or directory exists * {{{os.path.getsize()}}} Size of a file == Modules glob == === Example glob === |
Interaction with the operating system
The modules sys and os provide the basic interface to the operating system. The module os creates a portable abstraction layer which is used by high-level modules like glob, socket, thred, time, fcntl.
Module sys
The module sys provides access to system-specific parameters by the interpreter.
Example argv
run system1.py parameter1 parameter2 ['system1.py', 'parameter1', 'parameter2']
The script prints the command line arguments that are passed to the script. argv[0] is the script name
A more sophisticated way of evaluating command line arguments is provided by the module optparse
Module os
The module os is a portable operating system interface.
Some examples:
os.system() Executes the command (a string) in a subshell
os.mkdir() Creates a directory
os.remove() Deletes a file
os.path.isdir() Test if directory
os.path.isfile() Test if file
os.path.exists() Test if file or directory exists
os.path.getsize() Size of a file
Modules glob
Example glob