Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7b1aae9

Browse files
committed
#10960: fix 'stat' links, link to lstat from stat, general tidy of stat doc.
Original patch by Michal Nowikowski, with some additions and wording fixes by me. I changed the wording from 'Performs a stat system call' to 'Performs the equivalent of a stat system call', since on Windows there are no stat/lstat system calls involved. I also extended Michal's breakout of the attributes into a list to the other paragraphs, and rearranged the order of the paragraphs in the 'stat' docs to make it flow better and put it in what I think is a more logical/useful order.
1 parent a80ab10 commit 7b1aae9

2 files changed

Lines changed: 57 additions & 35 deletions

File tree

Doc/ACKS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ [email protected]), and we'll be glad to correct the problem.
140140
* Ross Moore
141141
* Sjoerd Mullender
142142
* Dale Nagata
143+
* Michal Nowikowski
143144
* Ng Pheng Siong
144145
* Koray Oner
145146
* Tomas Oppelstrup

Doc/library/os.rst

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ as internal buffering of data.
657657

658658
.. function:: fstat(fd)
659659

660-
Return status for file descriptor *fd*, like :func:`stat`.
660+
Return status for file descriptor *fd*, like :func:`~os.stat`.
661661

662662
Availability: Unix, Windows.
663663

@@ -1080,8 +1080,10 @@ Files and Directories
10801080

10811081
.. function:: lstat(path)
10821082

1083-
Like :func:`stat`, but do not follow symbolic links. This is an alias for
1084-
:func:`stat` on platforms that do not support symbolic links.
1083+
Perform the equivalent of an :c:func:`lstat` system call on the given path.
1084+
Similar to :func:`~os.stat`, but does not follow symbolic links. On
1085+
platforms that do not support symbolic links, this is an alias for
1086+
:func:`~os.stat`.
10851087

10861088
.. versionchanged:: 3.2
10871089
Added support for Windows 6.0 (Vista) symbolic links.
@@ -1276,62 +1278,81 @@ Files and Directories
12761278

12771279
.. function:: stat(path)
12781280

1279-
Perform a :c:func:`stat` system call on the given path. The return value is an
1280-
object whose attributes correspond to the members of the :c:type:`stat`
1281-
structure, namely: :attr:`st_mode` (protection bits), :attr:`st_ino` (inode
1282-
number), :attr:`st_dev` (device), :attr:`st_nlink` (number of hard links),
1283-
:attr:`st_uid` (user id of owner), :attr:`st_gid` (group id of owner),
1284-
:attr:`st_size` (size of file, in bytes), :attr:`st_atime` (time of most recent
1285-
access), :attr:`st_mtime` (time of most recent content modification),
1286-
:attr:`st_ctime` (platform dependent; time of most recent metadata change on
1287-
Unix, or the time of creation on Windows)::
1281+
Perform the equivalent of a :c:func:`stat` system call on the given path.
1282+
(This function follows symlinks; to stat a symlink use :func:`lstat`.)
12881283

1289-
>>> import os
1290-
>>> statinfo = os.stat('somefile.txt')
1291-
>>> statinfo
1292-
(33188, 422511, 769, 1, 1032, 100, 926, 1105022698,1105022732, 1105022732)
1293-
>>> statinfo.st_size
1294-
926
1284+
The return value is an object whose attributes correspond to the members
1285+
of the :c:type:`stat` structure, namely:
1286+
1287+
* :attr:`st_mode` - protection bits,
1288+
* :attr:`st_ino` - inode number,
1289+
* :attr:`st_dev` - device,
1290+
* :attr:`st_nlink` - number of hard links,
1291+
* :attr:`st_uid` - user id of owner,
1292+
* :attr:`st_gid` - group id of owner,
1293+
* :attr:`st_size` - size of file, in bytes,
1294+
* :attr:`st_atime` - time of most recent access,
1295+
* :attr:`st_mtime` - time of most recent content modification,
1296+
* :attr:`st_ctime` - platform dependent; time of most recent metadata change on
1297+
Unix, or the time of creation on Windows)
12951298

12961299
On some Unix systems (such as Linux), the following attributes may also be
1297-
available: :attr:`st_blocks` (number of blocks allocated for file),
1298-
:attr:`st_blksize` (filesystem blocksize), :attr:`st_rdev` (type of device if an
1299-
inode device). :attr:`st_flags` (user defined flags for file).
1300+
available:
1301+
1302+
* :attr:`st_blocks` - number of blocks allocated for file
1303+
* :attr:`st_blksize` - filesystem blocksize
1304+
* :attr:`st_rdev` - type of device if an inode device
1305+
* :attr:`st_flags` - user defined flags for file
13001306

13011307
On other Unix systems (such as FreeBSD), the following attributes may be
1302-
available (but may be only filled out if root tries to use them): :attr:`st_gen`
1303-
(file generation number), :attr:`st_birthtime` (time of file creation).
1308+
available (but may be only filled out if root tries to use them):
1309+
1310+
* :attr:`st_gen` - file generation number
1311+
* :attr:`st_birthtime` - time of file creation
13041312

13051313
On Mac OS systems, the following attributes may also be available:
1306-
:attr:`st_rsize`, :attr:`st_creator`, :attr:`st_type`.
13071314

1308-
.. index:: module: stat
1315+
* :attr:`st_rsize`
1316+
* :attr:`st_creator`
1317+
* :attr:`st_type`
1318+
1319+
.. note::
13091320

1310-
For backward compatibility, the return value of :func:`stat` is also accessible
1321+
The exact meaning and resolution of the :attr:`st_atime`, :attr:`st_mtime`, and
1322+
:attr:`st_ctime` members depends on the operating system and the file system.
1323+
For example, on Windows systems using the FAT or FAT32 file systems,
1324+
:attr:`st_mtime` has 2-second resolution, and :attr:`st_atime` has only 1-day
1325+
resolution. See your operating system documentation for details.
1326+
1327+
For backward compatibility, the return value of :func:`~os.stat` is also accessible
13111328
as a tuple of at least 10 integers giving the most important (and portable)
13121329
members of the :c:type:`stat` structure, in the order :attr:`st_mode`,
13131330
:attr:`st_ino`, :attr:`st_dev`, :attr:`st_nlink`, :attr:`st_uid`,
13141331
:attr:`st_gid`, :attr:`st_size`, :attr:`st_atime`, :attr:`st_mtime`,
13151332
:attr:`st_ctime`. More items may be added at the end by some implementations.
1333+
1334+
.. index:: module: stat
1335+
13161336
The standard module :mod:`stat` defines functions and constants that are useful
13171337
for extracting information from a :c:type:`stat` structure. (On Windows, some
13181338
items are filled with dummy values.)
13191339

1320-
.. note::
1340+
Example::
13211341

1322-
The exact meaning and resolution of the :attr:`st_atime`, :attr:`st_mtime`, and
1323-
:attr:`st_ctime` members depends on the operating system and the file system.
1324-
For example, on Windows systems using the FAT or FAT32 file systems,
1325-
:attr:`st_mtime` has 2-second resolution, and :attr:`st_atime` has only 1-day
1326-
resolution. See your operating system documentation for details.
1342+
>>> import os
1343+
>>> statinfo = os.stat('somefile.txt')
1344+
>>> statinfo
1345+
(33188, 422511, 769, 1, 1032, 100, 926, 1105022698,1105022732, 1105022732)
1346+
>>> statinfo.st_size
1347+
926
13271348

13281349
Availability: Unix, Windows.
13291350

13301351

13311352
.. function:: stat_float_times([newvalue])
13321353

13331354
Determine whether :class:`stat_result` represents time stamps as float objects.
1334-
If *newvalue* is ``True``, future calls to :func:`stat` return floats, if it is
1355+
If *newvalue* is ``True``, future calls to :func:`~os.stat` return floats, if it is
13351356
``False``, future calls return ints. If *newvalue* is omitted, return the
13361357
current setting.
13371358

@@ -1428,8 +1449,8 @@ Files and Directories
14281449
respectively. Whether a directory can be given for *path* depends on whether
14291450
the operating system implements directories as files (for example, Windows
14301451
does not). Note that the exact times you set here may not be returned by a
1431-
subsequent :func:`stat` call, depending on the resolution with which your
1432-
operating system records access and modification times; see :func:`stat`.
1452+
subsequent :func:`~os.stat` call, depending on the resolution with which your
1453+
operating system records access and modification times; see :func:`~os.stat`.
14331454

14341455
Availability: Unix, Windows.
14351456

0 commit comments

Comments
 (0)