cpython-withatomic / Doc / libppath.tex

The branch 'legacy-trunk' does not exist.
\section{Standard Module \sectcode{posixpath}}

This module implements some useful functions on POSIX pathnames.

\strong{Do not import this module directly.}  Instead, import the
module \code{os} and use \code{os.path}.

\renewcommand{\indexsubitem}{(in module posixpath)}

Return the base name of pathname
This is the second half of the pair returned by

Return the longest string that is a prefix of all strings in
is empty, return the empty string (\code{''}).

Return true if
refers to an existing path.

Return the argument with an initial component of \samp{\~} or
\samp{\~\var{user}} replaced by that \var{user}'s home directory.  An
initial \samp{\~{}} is replaced by the environment variable \code{\${}HOME};
an initial \samp{\~\var{user}} is looked up in the password directory through
the built-in module \code{pwd}.  If the expansion fails, or if the
path does not begin with a tilde, the path is returned unchanged.

Return the argument with environment variables expanded.  Substrings
of the form \samp{\$\var{name}} or \samp{\$\{\var{name}\}} are
replaced by the value of environment variable \var{name}.  Malformed
variable names and references to non-existing variables are left

Return true if \var{p} is an absolute pathname (begins with a slash).

Return true if \var{p} is an existing regular file.  This follows
symbolic links, so both \code{islink()} and \code{isfile()} can be true for the same

Return true if \var{p} is an existing directory.  This follows
symbolic links, so both \code{islink()} and \code{isdir()} can be true for the same

Return true if
refers to a directory entry that is a symbolic link.
Always false if symbolic links are not supported.

Return true if pathname \var{p} is a \dfn{mount point}: a point in a
file system where a different file system has been mounted.  The
function checks whether \var{p}'s parent, \file{\var{p}/..}, is on a
different device than \var{p}, or whether \file{\var{p}/..} and
\var{p} point to the same i-node on the same device --- this should
detect mount points for all \UNIX{} and POSIX variants.

\begin{funcdesc}{join}{p\optional{\, q\optional{\, ...}}}
Joins one or more path components intelligently.  If any component is
an absolute path, all previous components are thrown away, and joining
continues.  The return value is the concatenation of \var{p}, and
optionally \var{q}, etc., with exactly one slash (\code{'/'}) inserted
between components, unless \var{p} is empty.

Normalize the case of a pathname.  This returns the path unchanged;
however, a similar function in \code{macpath} converts upper case to
lower case.

\begin{funcdesc}{samefile}{p\, q}
Return true if both pathname arguments refer to the same file or directory
(as indicated by device number and i-node number).
Raise an exception if a stat call on either pathname fails.

Split the pathname \var{p} in a pair \code{(\var{head}, \var{tail})},
where \var{tail} is the last pathname component and \var{head} is
everything leading up to that.  The \var{tail} part will never contain
a slash; if \var{p} ends in a slash, \var{tail} will be empty.  If
there is no slash in \var{p}, \var{head} will be empty.  If \var{p} is
empty, both \var{head} and \var{tail} are empty.  Trailing slashes are
stripped from \var{head} unless it is the root (one or more slashes
only).  In nearly all cases, \code{join(\var{head}, \var{tail})}
equals \var{p} (the only exception being when there were multiple
slashes separating \var{head} from \var{tail}).

Split the pathname \var{p} in a pair \code{(\var{root}, \var{ext})}
such that \code{\var{root} + \var{ext} == \var{p}},
and \var{ext} is empty or begins with a period and contains
at most one period.

\begin{funcdesc}{walk}{p\, visit\, arg}
Calls the function \var{visit} with arguments
\code{(\var{arg}, \var{dirname}, \var{names})} for each directory in the
directory tree rooted at \var{p} (including \var{p} itself, if it is a
directory).  The argument \var{dirname} specifies the visited directory,
the argument \var{names} lists the files in the directory (gotten from
The \var{visit} function may modify \var{names} to
influence the set of directories visited below \var{dirname}, e.g., to
avoid visiting certain parts of the tree.  (The object referred to by
\var{names} must be modified in place, using \code{del} or slice