Change this to be os.path.

Use consistent parameter naming with the os documentation (paths
always named "path" or "path1", "path2"...).
This commit is contained in:
Fred Drake 1999-02-02 18:58:33 +00:00
parent bb79438d26
commit a9b9bf96fe

View File

@ -8,15 +8,15 @@ This module implements some useful functions on pathnames.
\index{path!operations} \index{path!operations}
\begin{funcdesc}{abspath}{p} \begin{funcdesc}{abspath}{path}
Return a normalized absolutized version of the pathname \var{p}. On Return a normalized absolutized version of the pathname \var{path}.
most platforms, this is equivalent to On most platforms, this is equivalent to
\code{normpath(join(os.getcwd()), \var{p})}. \code{normpath(join(os.getcwd()), \var{path})}.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{basename}{p} \begin{funcdesc}{basename}{path}
Return the base name of pathname \var{p}. This is the second half of Return the base name of pathname \var{path}. This is the second half
the pair returned by \code{split(\var{p})}. of the pair returned by \code{split(\var{path})}.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{commonprefix}{list} \begin{funcdesc}{commonprefix}{list}
@ -25,16 +25,16 @@ Return the longest string that is a prefix of all strings in
(\code{''}). (\code{''}).
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{dirname}{p} \begin{funcdesc}{dirname}{path}
Return the directory name of pathname \var{p}. This is the first half Return the directory name of pathname \var{path}. This is the first
of the pair returned by \code{split(\var{p})}. half of the pair returned by \code{split(\var{path})}.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{exists}{p} \begin{funcdesc}{exists}{path}
Return true if \var{p} refers to an existing path. Return true if \var{path} refers to an existing path.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{expanduser}{p} \begin{funcdesc}{expanduser}{path}
Return the argument with an initial component of \samp{\~} or Return the argument with an initial component of \samp{\~} or
\samp{\~\var{user}} replaced by that \var{user}'s home directory. An \samp{\~\var{user}} replaced by that \var{user}'s home directory. An
initial \samp{\~{}} is replaced by the environment variable initial \samp{\~{}} is replaced by the environment variable
@ -42,87 +42,87 @@ initial \samp{\~{}} is replaced by the environment variable
password directory through the built-in module password directory through the built-in module
\refmodule{pwd}\refbimodindex{pwd}. If the expansion fails, or if the \refmodule{pwd}\refbimodindex{pwd}. If the expansion fails, or if the
path does not begin with a tilde, the path is returned unchanged. On path does not begin with a tilde, the path is returned unchanged. On
the Macintosh, this always returns \var{p} unchanged. the Macintosh, this always returns \var{path} unchanged.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{expandvars}{p} \begin{funcdesc}{expandvars}{path}
Return the argument with environment variables expanded. Substrings Return the argument with environment variables expanded. Substrings
of the form \samp{\$\var{name}} or \samp{\$\{\var{name}\}} are of the form \samp{\$\var{name}} or \samp{\$\{\var{name}\}} are
replaced by the value of environment variable \var{name}. Malformed replaced by the value of environment variable \var{name}. Malformed
variable names and references to non-existing variables are left variable names and references to non-existing variables are left
unchanged. On the Macintosh, this always returns \var{p} unchanged. unchanged. On the Macintosh, this always returns \var{path}
unchanged.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{getsize}{filename} \begin{funcdesc}{getsize}{path}
\versionadded{1.5.2}
Return the size, in bytes, of \var{filename}. Raise Return the size, in bytes, of \var{filename}. Raise
\exception{os.error} if the file does not exist or is inaccessible. \exception{os.error} if the file does not exist or is inaccessible.
\versionadded{1.5.2}
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{getmtime}{filename} \begin{funcdesc}{getmtime}{path}
\versionadded{1.5.2}
Return the time of last modification of \var{filename}. The return Return the time of last modification of \var{filename}. The return
value is integer giving the number of seconds since the epoch (see the value is integer giving the number of seconds since the epoch (see the
\refmodule{time} module). Raise \exception{os.error} if the file does \refmodule{time} module). Raise \exception{os.error} if the file does
not exist or is inaccessible. not exist or is inaccessible.
\versionadded{1.5.2}
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{getatime}{filename} \begin{funcdesc}{getatime}{path}
\versionadded{1.5.2}
Return the time of last access of \var{filename}. The return Return the time of last access of \var{filename}. The return
value is integer giving the number of seconds since the epoch (see the value is integer giving the number of seconds since the epoch (see the
\refmodule{time} module). Raise \exception{os.error} if the file does \refmodule{time} module). Raise \exception{os.error} if the file does
not exist or is inaccessible. not exist or is inaccessible.
\versionadded{1.5.2}
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{isabs}{p} \begin{funcdesc}{isabs}{path}
Return true if \var{p} is an absolute pathname (begins with a slash). Return true if \var{path} is an absolute pathname (begins with a
slash).
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{isfile}{p} \begin{funcdesc}{isfile}{path}
Return true if \var{p} is an existing regular file. This follows Return true if \var{path} is an existing regular file. This follows
symbolic links, so both \function{islink()} and \function{isfile()} symbolic links, so both \function{islink()} and \function{isfile()}
can be true for the same path. can be true for the same path.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{isdir}{p} \begin{funcdesc}{isdir}{path}
Return true if \var{p} is an existing directory. This follows Return true if \var{path} is an existing directory. This follows
symbolic links, so both \function{islink()} and \function{isdir()} can symbolic links, so both \function{islink()} and \function{isdir()} can
be true for the same path. be true for the same path.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{islink}{p} \begin{funcdesc}{islink}{path}
Return true if Return true if \var{path} refers to a directory entry that is a
\var{p} symbolic link. Always false if symbolic links are not supported.
refers to a directory entry that is a symbolic link.
Always false if symbolic links are not supported.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{ismount}{p} \begin{funcdesc}{ismount}{path}
Return true if pathname \var{p} is a \dfn{mount point}: a point in a Return true if pathname \var{path} is a \dfn{mount point}: a point in
file system where a different file system has been mounted. The 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 function checks whether \var{path}'s parent, \file{\var{path}/..}, is
different device than \var{p}, or whether \file{\var{p}/..} and on a different device than \var{path}, or whether \file{\var{path}/..}
\var{p} point to the same i-node on the same device --- this should and \var{path} point to the same i-node on the same device --- this
detect mount points for all \UNIX{} and \POSIX{} variants. should detect mount points for all \UNIX{} and \POSIX{} variants.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{join}{p\optional{, q\optional{, ...}}} \begin{funcdesc}{join}{path1\optional{, path2\optional{, ...}}}
Joins one or more path components intelligently. If any component is Joins one or more path components intelligently. If any component is
an absolute path, all previous components are thrown away, and joining an absolute path, all previous components are thrown away, and joining
continues. The return value is the concatenation of \var{p}, and continues. The return value is the concatenation of \var{path1}, and
optionally \var{q}, etc., with exactly one slash (\code{'/'}) inserted optionally \var{path2}, etc., with exactly one slash (\code{'/'})
between components, unless \var{p} is empty. inserted between components, unless \var{path} is empty.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{normcase}{p} \begin{funcdesc}{normcase}{path}
Normalize the case of a pathname. On \UNIX{}, this returns the path Normalize the case of a pathname. On \UNIX{}, this returns the path
unchanged; on case-insensitive filesystems, it converts the path to unchanged; on case-insensitive filesystems, it converts the path to
lowercase. On Windows, it also converts forward slashes to backward lowercase. On Windows, it also converts forward slashes to backward
slashes. slashes.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{normpath}{p} \begin{funcdesc}{normpath}{path}
Normalize a pathname. This collapses redundant separators and Normalize a pathname. This collapses redundant separators and
up-level references, e.g. \code{A//B}, \code{A/./B} and up-level references, e.g. \code{A//B}, \code{A/./B} and
\code{A/foo/../B} all become \code{A/B}. It does not normalize the \code{A/foo/../B} all become \code{A/B}. It does not normalize the
@ -130,40 +130,41 @@ case (use \function{normcase()} for that). On Windows, it does
converts forward slashes to backward slashes. converts forward slashes to backward slashes.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{samefile}{p, q} \begin{funcdesc}{samefile}{path1, path2}
Return true if both pathname arguments refer to the same file or Return true if both pathname arguments refer to the same file or
directory (as indicated by device number and i-node number). directory (as indicated by device number and i-node number).
Raise an exception if a \function{os.stat()} call on either pathname Raise an exception if a \function{os.stat()} call on either pathname
fails. fails.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{split}{p} \begin{funcdesc}{split}{path}
Split the pathname \var{p} in a pair \code{(\var{head}, \var{tail})}, Split the pathname \var{path} in a pair \code{(\var{head},
where \var{tail} is the last pathname component and \var{head} is \var{tail})}, where \var{tail} is the last pathname component and
everything leading up to that. The \var{tail} part will never contain \var{head} is everything leading up to that. The \var{tail} part will
a slash; if \var{p} ends in a slash, \var{tail} will be empty. If never contain a slash; if \var{path} ends in a slash, \var{tail} will
there is no slash in \var{p}, \var{head} will be empty. If \var{p} is be empty. If there is no slash in \var{path}, \var{head} will be
empty, both \var{head} and \var{tail} are empty. Trailing slashes are empty. If \var{path} is empty, both \var{head} and \var{tail} are
stripped from \var{head} unless it is the root (one or more slashes empty. Trailing slashes are stripped from \var{head} unless it is the
only). In nearly all cases, \code{join(\var{head}, \var{tail})} root (one or more slashes only). In nearly all cases,
equals \var{p} (the only exception being when there were multiple \code{join(\var{head}, \var{tail})} equals \var{path} (the only
slashes separating \var{head} from \var{tail}). exception being when there were multiple slashes separating \var{head}
from \var{tail}).
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{splitext}{p} \begin{funcdesc}{splitext}{path}
Split the pathname \var{p} in a pair \code{(\var{root}, \var{ext})} Split the pathname \var{path} in a pair \code{(\var{root}, \var{ext})}
such that \code{\var{root} + \var{ext} == \var{p}}, such that \code{\var{root} + \var{ext} == \var{path}},
and \var{ext} is empty or begins with a period and contains and \var{ext} is empty or begins with a period and contains
at most one period. at most one period.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{walk}{p, visit, arg} \begin{funcdesc}{walk}{path, visit, arg}
Calls the function \var{visit} with arguments Calls the function \var{visit} with arguments
\code{(\var{arg}, \var{dirname}, \var{names})} for each directory in the \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 tree rooted at \var{path} (including \var{path} itself, if it
directory). The argument \var{dirname} specifies the visited directory, is a directory). The argument \var{dirname} specifies the visited
the argument \var{names} lists the files in the directory (gotten from directory, the argument \var{names} lists the files in the directory
\code{os.listdir(\var{dirname})}). (gotten from \code{os.listdir(\var{dirname})}).
The \var{visit} function may modify \var{names} to The \var{visit} function may modify \var{names} to
influence the set of directories visited below \var{dirname}, e.g., 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 avoid visiting certain parts of the tree. (The object referred to by