os – functions that an OS normally provides — Adafruit CircuitPython 1 documentation (original) (raw)

This module implements a subset of the corresponding CPython module, as described below. For more information, refer to the original CPython documentation: cpython:os.

Available on these boards

os.uname() → _Uname

Returns a named tuple of operating specific and CircuitPython port specific information.

class os._Uname

Bases: NamedTuple

The type of values that uname() returns

sysname_: str_

nodename_: str_

release_: str_

version_: str_

machine_: str_

os.chdir(path: str) → None

Change current directory.

os.getcwd() → str

Get the current directory.

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.

On boards that do not support settings.toml reading in the core, this function will raise NotImplementedError.

Available on these boards

os.listdir(dir: str) → str

With no argument, list the current directory. Otherwise list the given directory.

os.mkdir(path: str) → None

Create a new directory.

os.remove(path: str) → None

Remove a file.

os.rmdir(path: str) → None

Remove a directory.

os.rename(old_path: str, new_path: str) → str

Rename a file.

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:

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:

Parameters related to inodes: f_files, f_ffree, f_availand the f_flags parameter may return 0 as they can be unavailable in a port-specific implementation.

os.sync() → None

Sync all filesystems.

os.urandom(size: int) → str

Returns a string of size random bytes based on a hardware True Random Number Generator. When not available, it will raise a NotImplementedError.

Limitations: Not available on SAMD21 due to lack of hardware.

os.utime(path: str, times: Tuple[int, int]) → None

Change the timestamp of a file.

os.sep_: str_

Separator used to delineate path components such as folder and file names.