os
Native operating-system interfaces for POSIX and Windows.
POSIX paths and environment use UTF-8 with surrogateescape to preserve arbitrary
bytes; Windows uses wide-character APIs. Filesystem APIs currently accept str
paths only; fsencode() and fsdecode() additionally accept bytes and str
identity inputs, respectively.
Failures raise OSError with errno, a system diagnostic and applicable filenames
(plus winerror for Windows API failures). File-descriptor reads and writes may
transfer fewer bytes than requested. Windows permissions and available process
APIs differ from POSIX.
curdir: Literal[str] = "."
pardir: Literal[str] = ".."
extsep: Literal[str] = "."
SEEK_SET: Literal[int] = 0
SEEK_CUR: Literal[int] = 1
SEEK_END: Literal[int] = 2
F_OK: Literal[int] = 0
R_OK: Literal[int] = 4
W_OK: Literal[int] = 2
X_OK: Literal[int] = 1
O_RDONLY: Literal[int] = 0
O_WRONLY: Literal[int] = 1
O_RDWR: Literal[int] = 2
fspath(path)
fsencode(filename: str) -> bytes
fsencode(filename: bytes) -> bytes
fsdecode(filename: bytes) -> str
fsdecode(filename: str) -> str
system(cmd: str) -> int
putenv(key: str, value: str, /)
Set the process environment without updating the environ mapping.
unsetenv(key: str, /)
Remove a process variable without updating the environ mapping.
environ = _Environ(_make_env_map(), copy=False)
getenv(key: str, default = None)
class stat_result
Fields
14
st_mode
int
st_ino
int
st_dev
int
st_nlink
int
st_uid
int
st_gid
int
st_size
int
st_atime
float
st_mtime
float
st_ctime
float
st_atime_ns
int
st_mtime_ns
int
st_ctime_ns
int
st_rdev
int
Constructors
2
Special methods
4
stat(path: str, *, follow_symlinks: bool = True) -> stat_result
stat(fd: int) -> stat_result
fstat(fd: int) -> stat_result
lstat(path: str) -> stat_result
open(path: str, flags: int, mode: int = 0o777) -> int
listdir(path: str = ".") -> List[str]
makedirs(name: str, mode: int = 0o777, exist_ok: bool = False)
removedirs(name: str)
mkdir(path: str, mode: int = 0o777)
rmdir(path: str)
chdir(path: str)
getcwdb() -> bytes
getcwd() -> str
unlink(path: str)
remove(path: str)
rename(src: str, dst: str)
replace(src: str, dst: str)
link(src: str, dst: str)
symlink(src: str, dst: str, target_is_directory: bool = False)
readlink(path: str) -> str
access(path: str, mode: int) -> bool
chmod(path: str, mode: int, *, follow_symlinks: bool = True)
getpid() -> int
getppid() -> int
close(fd: int)
read(fd: int, n: int, /) -> bytes
write(fd: int, data: bytes, /) -> int
lseek(fd: int, pos: int, how: int, /) -> int
fsync(fd: int)
ftruncate(fd: int, length: int, /)
truncate(path: str, length: int)
Modules
4