
The os System Module
|
95
altsep
Alternative separator string or None (e.g., / for Windows).
extsep
The character which separates the base filename from the
extension (e.g.,
.).
pathsep
Character used to separate search path components, as
in
the
PATH
and
PYTHONPATH
shell variable settings (e.g.,
;
for
Windows,
:
for Unix).
defpath
Default search path used by os.exec*p* calls if there is no
PATH setting in the shell.
linesep
String used to terminate lines on current platform (e.g.,
\n
for POSIX,
\r
for Mac OS, and
\r\n
for MS-DOS and
Windows).
Shell Commands
These functions run programs in the underlying operating
system.
system(cmd)
Executes a command string cmd in a subshell process.
Returns the exit status of the spawned process. Unlike
popen, does not connect to cmd’s standard streams via
pipes. Hints: add an
& at the end of cmd to run the com-
mand in the background on Unix (e.g.,
os.
system('python main.py &')
); use a DOS start command
to launch programs easily on Windows (e.g.,
os.
system('start file.html')
).
startfile(filepathname)
Starts a file with its associated application. Acts like dou-
ble-clicking the file in Windows Explorer or giving the
filename as an argument to a DOS
start command (e.g.,
with
os.system('start path')). The file is opened in the