os
– functions that an OS normally provides
This module implements a subset of the corresponding CPython module,
as described below. For more information, refer to the original
CPython documentation: os
.
Available on these boards
- os.uname() _Uname
Returns a named tuple of operating specific and CircuitPython port specific information.
- os.getenv(key: str, default: str | None = None) str | None
Get the environment variable value for the given key or return
default
.This may load values from disk so cache the result instead of calling this often.
- os.listdir(dir: str) str
With no argument, list the current directory. Otherwise list the given directory.
- os.stat(path: str) Tuple[int, int, int, int, int, int, int, int, int, int]
Get the status of a file or directory.
Returns a tuple with the status of a file or directory in the following order:
st_mode
– File type, regular or directoryst_ino
– Set to 0st_dev
– Set to 0st_nlink
– Set to 0st_uid
– Set to 0st_gid
– Set to 0st_size
– Size of the file in bytesst_atime
– Time of most recent access expressed in secondsst_mtime
– Time of most recent content modification expressed in seconds.st_ctime
– Time of most recent content modification expressed in seconds.
Note
On builds without long integers, the number of seconds for contemporary dates will not fit in a small integer. So the time fields return 946684800, which is the number of seconds corresponding to 1999-12-31.
- os.statvfs(path: str) Tuple[int, int, int, int, int, int, int, int, int, int]
Get the status of a filesystem.
Returns a tuple with the filesystem information in the following order:
f_bsize
– file system block sizef_frsize
– fragment sizef_blocks
– size of fs in f_frsize unitsf_bfree
– number of free blocksf_bavail
– number of free blocks for unprivileged usersf_files
– number of inodesf_ffree
– number of free inodesf_favail
– number of free inodes for unprivileged usersf_flag
– mount flagsf_namemax
– maximum filename length
Parameters related to inodes:
f_files
,f_ffree
,f_avail
and thef_flags
parameter may return0
as they can be unavailable in a port-specific implementation.