The variables and methods in the os module
allow you to interact with files and directories. In most
cases the names and functionalities are the same as the
equivalent C language functions, so refer to Kernighan and
Ritchie, The C Programming Language,
second edition, or the equivalent for more details.
chdir(p)
Change the current working directory to that given by
string p
chmod(p,m)
Change the permissions for pathname to p. See module mstat, below, for symbolic constants to be used in
making up
values.
m
chown(p,u,g)
Change the owner of pathname to user id p and group id u.
g
environA dictionary whose keys are the names of all currently defined environmental variables, and whose values are the values of those variables.
errorThe exception raised for errors in this module.
execv(p,A)
Replace the current process with a new process executing
the file at pathname , where p is a list of the strings to be passed to the
new process as command line arguments.
A
execve(p,A,E)
Like execv(), but you supply a dictionary
that
defines the environmental variables for the new process.
E
_exit(n)
Exit the current process and return status code . This method
should be used only by the child process after a nfork(); normally you should use sys.exit().
fork()
Fork a child process. In the child process, this
function returns 0; in the parent, it
returns the child's process ID.
getcwd()Returns the current working directory name as a string.
getegid()Returns the effective group ID.
geteuid()Returns the effective user ID.
getgid()
Returns the current process's group ID. To decode
user IDs, see the grp standard module.
getpid()Returns the current process's process ID.
getppid()Returns the parent process's PID (process ID).
getuid()
Returns the current process's user ID. To decode
user IDs, see the pwd standard module.
kill(p,s)
Send signal to the process whose process ID is s.
p
link(s,d)
Create a hard link to and call the link s.
d
listdir(p)
Return a list of the names of the files in the directory
whose pathname is . This list will never contain the special
entries p'.' and '..' for
the current and parent directories. The entries may not
be in any particular order.
lstat(p)
Like stat(), but if is a link, you will get the
status tuple for the link itself, rather than the file
it points at.
p
makedirs(p[,
mode])
Works like mkdir(), but will also
create any intermediate directories between existing
directories and the desired new directory.
mkdir(p[,m])
Create a directory at pathname . You may optionally specify
permissions p; see module mstat below for the interpretation of
permission values.
mkfifo(p,m)
Create a named pipe with name and open mode p. The server
side of the pipe will open it for reading, and the
client side for writing. This function does not
actually open the fifo, it just creates the rendezvous
point.
m
nice(i)
Renice (change the priority) of the current process by
adding to
its current priority.
i
readlink(p)
If is the
pathname to a soft (symbolic) link, this function
returns the pathname to which that link points.
p
remove(p)
Removes the file with pathname , as in the Unix prm command. Raises OSError if
it fails.
removedirs(p)
Similar to remove(), but also removes
any other parent directory in the path that has no
other children.
rename(po, pn)
Rename path to po.
pn
rmdir(p)
Remove the directory at path .
p
stat(p)
Return a status tuple describing the file or directory
at pathname . See module pstat, below, for the
interpretation of a status tuple. If is a link, you
will get the status tuple of the file to which p is linked.
p
symlink(s,d)
Create a symbolic link to path , and call the link s.
d
system(c)
Execute the command in string as a sub-shell. Returns the
exit status of the process.
c
times()
Returns a tuple of statistics about the current
process's elapsed time. This tuple has the form ( where u,s,u',s',r) is user time, u is system time,
s and u' are user and
system time including all child processes, and s' is elapsed real
time. All values are in seconds as floats.
r
tmpfile()
Returns a new, open temporary file, with update mode
"w+b". This file will not appear in any
directory, and will disappear when it is no longer in
use.
umask(m)
Sets the “umask” that determines the default permissions for newly created files. Returns the previous value. Each bit set in the umask corresponds to a permission that is not granted by default.
uname()
Returns a tuple of strings descriping the operating
system's version:
(s,n,r,v,m) where
is the name of the operating system,
s
is the name of the processor (node) where you are running,
n
is the operating system's version number,
r
is the major version, and
v
describes the type of processor.
m
urandom(n)
Return a string of random bytes. These bytes should be
sufficiently random for use in cryptographic
applications.
n
utime(p,t)
The
argument must be a tuple t( where a, m)
and a are
epoch times. For pathname m, set the last access time to
p and the
last modification to a.
m
wait()
Wait for the termination of a child process. Returns a
tuple ( where p,e) is the child's
process ID and p is its exit status.
e
waitpid(p,o)
Like wait(), but it waits for the process
whose ID is . The option value p specifies what to do if the child is still
running. If o is 0, you wait for the child to terminate. Use a
value of oos.WNOHANG if you don't want to
wait.
WNOHANG
See waitpid() above.