Patch #658927: Add getctime to os.path.

Document that getatime and getmtime may return floats.
This commit is contained in:
Martin v. Löwis 2002-12-31 13:11:54 +00:00
parent 24a880b499
commit 96a60e4af5
6 changed files with 30 additions and 6 deletions

View File

@ -67,18 +67,28 @@ unchanged.
\begin{funcdesc}{getatime}{path} \begin{funcdesc}{getatime}{path}
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 a number 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} \versionadded{1.5.2}
\versionchanged[If \function{os.stat_float_times()} returns True, the result is a floating point number]{2.3}
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{getmtime}{path} \begin{funcdesc}{getmtime}{path}
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 a number 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} \versionadded{1.5.2}
\versionchanged[If \function{os.stat_float_times()} returns True, the result is a floating point number]{2.3}
\end{funcdesc}
\begin{funcdesc}{getctime}{path}
Return the time of creation of \var{filename}. The return
value is a number giving the number of seconds since the epoch (see the
\refmodule{time} module). Raise \exception{os.error} if the file does
not exist or is inaccessible.
\versionadded{2.3}
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{getsize}{path} \begin{funcdesc}{getsize}{path}

View File

@ -5,7 +5,7 @@ from stat import *
__all__ = ["normcase","isabs","join","splitdrive","split","splitext", __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
"basename","dirname","commonprefix","getsize","getmtime", "basename","dirname","commonprefix","getsize","getmtime",
"getatime","islink","exists","isdir","isfile", "getatime","getctime", "islink","exists","isdir","isfile",
"walk","expanduser","expandvars","normpath","abspath", "walk","expanduser","expandvars","normpath","abspath",
"supports_unicode_filenames"] "supports_unicode_filenames"]
@ -129,6 +129,9 @@ def isfile(s):
return False return False
return S_ISREG(st.st_mode) return S_ISREG(st.st_mode)
def getctime(filename):
"""Return the creation time of a file, reported by os.stat()."""
return os.stat(filename).st_ctime
def exists(s): def exists(s):
"""Return True if the pathname refers to an existing file or directory.""" """Return True if the pathname refers to an existing file or directory."""

View File

@ -11,7 +11,7 @@ import sys
__all__ = ["normcase","isabs","join","splitdrive","split","splitext", __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
"basename","dirname","commonprefix","getsize","getmtime", "basename","dirname","commonprefix","getsize","getmtime",
"getatime","islink","exists","isdir","isfile","ismount", "getatime","getctime", "islink","exists","isdir","isfile","ismount",
"walk","expanduser","expandvars","normpath","abspath","splitunc", "walk","expanduser","expandvars","normpath","abspath","splitunc",
"supports_unicode_filenames"] "supports_unicode_filenames"]
@ -220,6 +220,9 @@ def getatime(filename):
"""Return the last access time of a file, reported by os.stat()""" """Return the last access time of a file, reported by os.stat()"""
return os.stat(filename).st_atime return os.stat(filename).st_atime
def getctime(filename):
"""Return the creation time of a file, reported by os.stat()."""
return os.stat(filename).st_ctime
# Is a path a symbolic link? # Is a path a symbolic link?
# This will always return false on systems where posix.lstat doesn't exist. # This will always return false on systems where posix.lstat doesn't exist.

View File

@ -10,7 +10,7 @@ import stat
__all__ = ["normcase","isabs","join","splitdrive","split","splitext", __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
"basename","dirname","commonprefix","getsize","getmtime", "basename","dirname","commonprefix","getsize","getmtime",
"getatime","islink","exists","isdir","isfile","ismount", "getatime","getctime", "islink","exists","isdir","isfile","ismount",
"walk","expanduser","expandvars","normpath","abspath","splitunc", "walk","expanduser","expandvars","normpath","abspath","splitunc",
"supports_unicode_filenames"] "supports_unicode_filenames"]
@ -186,6 +186,9 @@ def getatime(filename):
"""Return the last access time of a file, reported by os.stat()""" """Return the last access time of a file, reported by os.stat()"""
return os.stat(filename).st_atime return os.stat(filename).st_atime
def getctime(filename):
"""Return the creation time of a file, reported by os.stat()."""
return os.stat(filename).st_ctime
# Is a path a symbolic link? # Is a path a symbolic link?
# This will always return false on systems where posix.lstat doesn't exist. # This will always return false on systems where posix.lstat doesn't exist.

View File

@ -15,7 +15,7 @@ import stat
__all__ = ["normcase","isabs","join","splitdrive","split","splitext", __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
"basename","dirname","commonprefix","getsize","getmtime", "basename","dirname","commonprefix","getsize","getmtime",
"getatime","islink","exists","isdir","isfile","ismount", "getatime","getctime","islink","exists","isdir","isfile","ismount",
"walk","expanduser","expandvars","normpath","abspath", "walk","expanduser","expandvars","normpath","abspath",
"samefile","sameopenfile","samestat","supports_unicode_filenames"] "samefile","sameopenfile","samestat","supports_unicode_filenames"]
@ -137,6 +137,9 @@ def getatime(filename):
"""Return the last access time of a file, reported by os.stat().""" """Return the last access time of a file, reported by os.stat()."""
return os.stat(filename).st_atime return os.stat(filename).st_atime
def getctime(filename):
"""Return the creation time of a file, reported by os.stat()."""
return os.stat(filename).st_ctime
# Is a path a symbolic link? # Is a path a symbolic link?
# This will always return false on systems where os.lstat doesn't exist. # This will always return false on systems where os.lstat doesn't exist.

View File

@ -463,6 +463,8 @@ Extension modules
Library Library
------- -------
- os.path exposes getctime.
- unittest.py now has two additional methods called assertAlmostEqual() - unittest.py now has two additional methods called assertAlmostEqual()
and failIfAlmostEqual(). They implement an approximate comparision and failIfAlmostEqual(). They implement an approximate comparision
by rounding the difference between the two arguments and comparing by rounding the difference between the two arguments and comparing