Skip to content

Commit 45523e0

Browse files
committed
gh-137970:add st_mode_notice code_example
1 parent fc0305a commit 45523e0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Doc/library/os.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3141,6 +3141,23 @@ features:
31413141

31423142
File mode: file type and file mode bits (permissions).
31433143

3144+
.. note::
3145+
3146+
``st_mode`` is an **int** bitmask that combines the file type and the
3147+
permission bits. If you expect POSIX-style values like ``755`` or ``644``,
3148+
render the value in octal and/or mask out only the permission bits. For example:
3149+
3150+
.. code-block:: pycon
3151+
3152+
>>> import os, stat
3153+
>>> m = os.stat("somefile").st_mode
3154+
>>> oct(m) # includes the file-type bits (e.g. 0o100...)
3155+
'0o100755'
3156+
>>> oct(stat.S_IMODE(m)) # permissions only
3157+
'0o755'
3158+
>>> stat.filemode(m) # human-readable form
3159+
'-rwxr-xr-x'
3160+
31443161
.. attribute:: st_ino
31453162

31463163
Platform dependent, but if non-zero, uniquely identifies the

0 commit comments

Comments
 (0)