Staging: this is not the live site, pydocs.org.
Generic Operating System Services os OS routines for NT or Posix depending on what system we're on.
This exports:
- all functions from posix or nt, e.g. unlink, stat, etc.
- os.path is either posixpath or ntpath
- os.name is either 'posix' or 'nt'
- os.curdir is a string representing the current directory (always '.')
- os.pardir is a string representing the parent directory (always '..')
- os.sep is the (or a most common) pathname separator ('/' or '\\')
- os.extsep is the extension separator (always '.')
- os.altsep is the alternate pathname separator (None or '/')
- os.pathsep is the component separator used in $PATH etc
- os.linesep is the line separator in text files ('\n' or '\r\n')
- os.defpath is the default search path for executables
- os.devnull is the file path of the null device ('/dev/null', etc.)
Programs that import and use 'os' stand a better chance of being
portable between different platforms. Of course, they must then
only use functions that are defined by all platforms (e.g., unlink
and opendir), and leave all pathname manipulation to os.path
(e.g., split and join). © Python Software Foundation. PSF License Version 2 · Official docs ↗
Symbols in os _ _exit Exit to the system with specified status, without normal exit processing. a abort Abort the interpreter immediately. access Use the real uid/gid to test for access to a path. altsep An alternative character used by the operating system to separate pathname components, or None if only one separator character exists. AT_NO_AUTOMOUNT If the final component of a path is an automount point, operate on the automount point instead of performing the automount. c chdir Change the current working directory to the specified path. chflags Set the flags of path to the numeric flags. chmod Change the access permissions of a file. chown Change the owner and group id of path to the numeric uid and gid. chroot Change root directory to path. CLD_CONTINUED These are the possible values for si_code in the result returned by waitid(). CLD_DUMPED These are the possible values for si_code in the result returned by waitid(). CLD_EXITED These are the possible values for si_code in the result returned by waitid(). CLD_KILLED These are the possible values for si_code in the result returned by waitid(). CLD_STOPPED These are the possible values for si_code in the result returned by waitid(). CLD_TRAPPED These are the possible values for si_code in the result returned by waitid(). close Close a file descriptor. closerange Closes all file descriptors in [fd_low, fd_high), ignoring errors. confstr Return a string-valued system configuration variable. confstr_names Dictionary mapping names accepted by confstr() to the integer values defined for those names by the host operating system. cpu_count Return the number of logical CPUs in the system. ctermid Return the name of the controlling terminal for this process. curdir The constant string used by the operating system to refer to the current directory. d defpath The default search path used by exec*p* and spawn*p* if the environment doesn’t have a 'PATH' key. device_encoding Return a string describing the encoding of a terminal's file descriptor. devnull The file path of the null device. DirEntry Object yielded by scandir() to expose the file path and other file attributes of a directory entry. dup Return a duplicate of a file descriptor. dup2 Duplicate file descriptor. e EFD_CLOEXEC Set close-on-exec flag for new eventfd() file descriptor. EFD_NONBLOCK Set O_NONBLOCK status flag for new eventfd() file descriptor. EFD_SEMAPHORE Provide semaphore-like semantics for reads from an eventfd() file descriptor. environ A mapping object where keys and values are strings that represent the process environment. environb Bytes version of environ: a mapping object where both keys and values are bytes objects representing the process environment. error Base class for I/O related errors. eventfd Creates and returns an event notification file descriptor. EX_CANTCREAT Exit code that means a user specified output file could not be created. EX_CONFIG Exit code that means that some kind of configuration error occurred. EX_DATAERR Exit code that means the input data was incorrect. EX_IOERR Exit code that means that an error occurred while doing I/O on some file. EX_NOHOST Exit code that means a specified host did not exist. EX_NOINPUT Exit code that means an input file did not exist or was not readable. EX_NOPERM Exit code that means that there were insufficient permissions to perform the operation (but not intended for file system problems). EX_NOTFOUND Exit code that means something like “an entry was not found”. EX_NOUSER Exit code that means a specified user did not exist. EX_OK Exit code that means no error occurred. EX_OSERR Exit code that means an operating system error was detected, such as the inability to fork or create a pipe. EX_OSFILE Exit code that means some system file did not exist, could not be opened, or had some other kind of error. EX_PROTOCOL Exit code that means that a protocol exchange was illegal, invalid, or not understood. EX_SOFTWARE Exit code that means an internal software error was detected. EX_TEMPFAIL Exit code that means a temporary failure occurred. EX_UNAVAILABLE Exit code that means that a required service is unavailable. EX_USAGE Exit code that means the command was used incorrectly, such as when the wrong number of arguments are given. execl Execute the executable file with argument list args, replacing the current process. execle Execute the executable file with argument list args and environment env, replacing the current process. execlp Execute the executable file (which is searched for along $PATH) with argument list args, replacing the current process. execlpe Execute the executable file (which is searched for along $PATH) with argument list args and environment env, replacing the current process. execv Execute an executable path with arguments, replacing current process. execve Execute an executable path with arguments, replacing current process. execvp Execute the executable file (which is searched for along $PATH) with argument list args, replacing the current process. execvpe Execute the executable file (which is searched for along $PATH) with argument list args and environment env, replacing the current process. extsep The character which separates the base filename from the extension; for example, the '.' in os.py. f F_LOCK Flags that specify what action lockf() will take. F_OK Values to pass as the mode parameter of access() to test the existence, readability, writability and executability of path, respectively. F_TEST Flags that specify what action lockf() will take. F_TLOCK Flags that specify what action lockf() will take. F_ULOCK Flags that specify what action lockf() will take. fchdir Change to the directory of the given file descriptor. fchmod Change the access permissions of the file given by file descriptor fd. fchown Change the owner and group id of the file specified by file descriptor. fdatasync Force write of fd to disk without forcing update of metadata. fdopen Return an open file object connected to the file descriptor fd. fork Fork a child process. forkpty Fork a new process with a new pseudo-terminal as controlling tty. fpathconf Return the configuration limit name for the file descriptor fd. fsdecode Decode filename (an os.PathLike, bytes, or str) from the filesystem encoding with 'surrogateescape' error handler, return str unchanged. fsencode Encode filename (an os.PathLike, bytes, or str) to the filesystem encoding with 'surrogateescape' error handler, return bytes unchanged. fspath Return the file system path representation of the object. fstat Perform a stat system call on the given file descriptor. fstatvfs Perform an fstatvfs system call on the given fd. fsync Force write of fd to disk. ftruncate Truncate a file, specified by file descriptor, to a specific length. fwalk Directory tree generator. g get_exec_path Returns the sequence of directories that will be searched for the named executable (similar to a shell) when launching a process. getcwd Return a unicode string representing the current working directory. getcwdb Return a bytes string representing the current working directory. getegid Return the current process's effective group id. getenv Get an environment variable, return None if it doesn't exist. getenvb Get an environment variable, return None if it doesn't exist. geteuid Return the current process's effective user id. getgid Return the current process's group id. getgrouplist Returns a list of groups to which a user belongs. getgroups Return list of supplemental group IDs for the process. getloadavg Return average recent system load information. getpgid Call the system call getpgid(), and return the result. getpgrp Return the current process group id. getpid Return the current process id. getppid Return the parent's process id. getresgid Return a tuple of the current process's real, effective, and saved group ids. getresuid Return a tuple of the current process's real, effective, and saved user ids. getsid Call the system call getsid(pid) and return the result. getuid Return the current process's user id. getxattr Return the value of extended attribute attribute on path. grantpt Grant access to the slave pseudo-terminal device. GRND_NONBLOCK By default, when reading from /dev/random, getrandom() blocks if no random bytes are available, and when reading from /dev/urandom, it blocks if the entropy pool has not yet been initialized. GRND_RANDOM If this bit is set, then random bytes are drawn from the /dev/random pool instead of the /dev/urandom pool. i isatty Return True if the fd is connected to a terminal. k kill Kill a process with a signal. killpg Kill a process group with a signal. l lchflags Set the flags of path to the numeric flags, like chflags(), but do not follow symbolic links. lchmod Change the mode of path to the numeric mode. lchown Change the owner and group id of path to the numeric uid and gid. linesep The string used to separate (or, rather, terminate) lines on the current platform. link Create a hard link to a file. listdir Return a list containing the names of the files in the directory. listdrives Return a list containing the names of drives on a Windows system. listmounts Return a list containing the mount points for a volume on a Windows system. listvolumes Return a list containing the volumes in the system. listxattr Return a list of extended attributes on path. lockf Apply, test or remove a POSIX lock on an open file descriptor. login_tty Prepare the tty of which fd is a file descriptor for a new login session. lseek Set the position of a file descriptor. lstat Perform a stat system call on the given path, without following symbolic links. m major Extracts a device major number from a raw device number. makedev Composes a raw device number from the major and minor device numbers. makedirs Super-mkdir; create a leaf directory and all intermediate ones. memfd_create Create an anonymous file and return a file descriptor that refers to it. MFD_CLOEXEC These flags can be passed to memfd_create(). MFD_HUGETLB These flags can be passed to memfd_create(). minor Extracts a device minor number from a raw device number. mkfifo Create a "fifo" (a POSIX named pipe). mknod Create a node in the file system. n name The name of the operating system dependent module imported. nice Add increment to the priority of process and return the new priority. NODEV Non-existent device. o O_APPEND The above constants are available on Unix and Windows. O_ASYNC The above constants are extensions and not present if they are not defined by the C library. O_BINARY The above constants are only available on Windows. O_CLOEXEC The above constants are only available on Unix. O_CREAT The above constants are available on Unix and Windows. O_DIRECT The above constants are extensions and not present if they are not defined by the C library. O_DIRECTORY The above constants are extensions and not present if they are not defined by the C library. O_DSYNC The above constants are only available on Unix. O_EVTONLY The above constants are only available on macOS. O_EXCL The above constants are available on Unix and Windows. O_EXLOCK The above constants are extensions and not present if they are not defined by the C library. O_FSYNC The above constants are only available on macOS. O_NDELAY The above constants are only available on Unix. O_NOATIME The above constants are extensions and not present if they are not defined by the C library. O_NOCTTY The above constants are only available on Unix. O_NOFOLLOW The above constants are extensions and not present if they are not defined by the C library. O_NOINHERIT The above constants are only available on Windows. O_NONBLOCK The above constants are only available on Unix. O_PATH The above constants are extensions and not present if they are not defined by the C library. O_RANDOM The above constants are only available on Windows. O_RDONLY The above constants are available on Unix and Windows. O_RDWR The above constants are available on Unix and Windows. O_RSYNC The above constants are only available on Unix. O_SEQUENTIAL The above constants are only available on Windows. O_SHLOCK The above constants are extensions and not present if they are not defined by the C library. O_SYMLINK The above constants are only available on macOS. O_SYNC The above constants are only available on Unix. O_TEMPORARY The above constants are only available on Windows. O_TEXT The above constants are only available on Windows. O_TMPFILE The above constants are extensions and not present if they are not defined by the C library. O_TRUNC The above constants are available on Unix and Windows. O_WRONLY The above constants are available on Unix and Windows. open Open a file for low level IO. p P_ALL These are the possible values for idtype in waitid(). P_DETACH Possible values for the mode parameter to the spawn* family of functions. P_NOWAIT Possible values for the mode parameter to the spawn* family of functions. P_NOWAITO Possible values for the mode parameter to the spawn* family of functions. P_OVERLAY Possible values for the mode parameter to the spawn* family of functions. P_PGID These are the possible values for idtype in waitid(). P_PID These are the possible values for idtype in waitid(). P_PIDFD These are the possible values for idtype in waitid(). P_WAIT Possible value for the mode parameter to the spawn* family of functions. pardir The constant string used by the operating system to refer to the parent directory. pathconf Return the configuration limit name for the file or directory path. pathconf_names Dictionary mapping names accepted by pathconf() and fpathconf() to the integer values defined for those names by the host operating system. PathLike Abstract base class for implementing the file system path protocol. pathsep The character conventionally used by the operating system to separate search path components (as in PATH), such as ':' for POSIX or ';' for Windows. PIDFD_NONBLOCK This flag indicates that the file descriptor will be non-blocking. pidfd_open Return a file descriptor referring to the process *pid*. pipe2 Create a pipe with flags set atomically. plock Lock program segments into memory. popen Open a pipe to or from command cmd. POSIX_FADV_DONTNEED Flags that can be used in advice in posix_fadvise() that specify the access pattern that is likely to be used. POSIX_FADV_NOREUSE Flags that can be used in advice in posix_fadvise() that specify the access pattern that is likely to be used. POSIX_FADV_NORMAL Flags that can be used in advice in posix_fadvise() that specify the access pattern that is likely to be used. POSIX_FADV_RANDOM Flags that can be used in advice in posix_fadvise() that specify the access pattern that is likely to be used. POSIX_FADV_SEQUENTIAL Flags that can be used in advice in posix_fadvise() that specify the access pattern that is likely to be used. POSIX_FADV_WILLNEED Flags that can be used in advice in posix_fadvise() that specify the access pattern that is likely to be used. posix_fadvise Announce an intention to access data in a specific pattern. posix_fallocate Ensure a file has allocated at least a particular number of bytes on disk. posix_openpt Open and return a file descriptor for a master pseudo-terminal device. posix_spawn Execute the program specified by path in a new process. posix_spawnp Execute the program specified by path in a new process. pread Read a number of bytes from a file descriptor starting at a particular offset. preadv Reads from a file descriptor into a number of mutable bytes-like objects. PRIO_DARWIN_BG Parameters for the getpriority() and setpriority() functions. PRIO_PGRP Parameters for the getpriority() and setpriority() functions. PRIO_PROCESS Parameters for the getpriority() and setpriority() functions. PRIO_USER Parameters for the getpriority() and setpriority() functions. ptsname Return the name of the slave pseudo-terminal device. putenv Change or add an environment variable. pwrite Write bytes to a file descriptor starting at a particular offset. pwritev Writes the contents of bytes-like objects to a file descriptor at a given offset. r R_OK Values to pass as the mode parameter of access() to test the existence, readability, writability and executability of path, respectively. read Read from a file descriptor. readinto Read into a buffer object from a file descriptor. readlink Return a string representing the path to which the symbolic link points. readv Read from a file descriptor fd into an iterable of buffers. reload_environ The os.environ and os.environb mappings are a cache of environment variables at the time that Python started. remove Remove a file (same as unlink()). removedirs Super-rmdir; remove a leaf directory and all empty intermediate ones. removexattr Remove extended attribute attribute on path. rename Rename a file or directory. renames Super-rename; create directories as necessary and delete any left empty. replace Rename a file or directory, overwriting the destination. RTLD_DEEPBIND Flags for use with the setdlopenflags() and getdlopenflags() functions. RTLD_GLOBAL Flags for use with the setdlopenflags() and getdlopenflags() functions. RTLD_LAZY Flags for use with the setdlopenflags() and getdlopenflags() functions. RTLD_LOCAL Flags for use with the setdlopenflags() and getdlopenflags() functions. RTLD_NODELETE Flags for use with the setdlopenflags() and getdlopenflags() functions. RTLD_NOLOAD Flags for use with the setdlopenflags() and getdlopenflags() functions. RTLD_NOW Flags for use with the setdlopenflags() and getdlopenflags() functions. RWF_APPEND Provide a per-write equivalent of the O_APPEND os.open() flag. RWF_DSYNC Provide a per-write equivalent of the O_DSYNC os.open() flag. RWF_NOWAIT Do not wait for data which is not immediately available. RWF_SYNC Provide a per-write equivalent of the O_SYNC os.open() flag. s scandir Return an iterator of DirEntry objects for given path. SCHED_BATCH Scheduling policy for CPU-intensive processes that tries to preserve interactivity on the rest of the computer. sched_getaffinity Return the affinity of the process identified by pid (or the current process if zero). sched_getparam Returns scheduling parameters for the process identified by pid. SCHED_IDLE Scheduling policy for extremely low priority background tasks. sched_param Currently has only one field: sched_priority SCHED_RR A round-robin scheduling policy. sched_setparam Set scheduling parameters for the process identified by pid. SEEK_CUR Parameters to the lseek() function and the seek() method on file-like objects, for whence to adjust the file position indicator. SEEK_DATA Parameters to the lseek() function and the seek() method on file-like objects, for seeking file data and holes on sparsely allocated files. SEEK_END Parameters to the lseek() function and the seek() method on file-like objects, for whence to adjust the file position indicator. SEEK_HOLE Parameters to the lseek() function and the seek() method on file-like objects, for seeking file data and holes on sparsely allocated files. SEEK_SET Parameters to the lseek() function and the seek() method on file-like objects, for whence to adjust the file position indicator. sendfile Copy count bytes from file descriptor in_fd to file descriptor out_fd. sep The character used by the operating system to separate pathname components. set_blocking Set the blocking mode of the specified file descriptor. setegid Set the current process's effective group id. seteuid Set the current process's effective user id. setgid Set the current process's group id. setgroups Set the groups of the current process to list. setns Move the calling thread into different namespaces. setpgid Call the system call setpgid(pid, pgrp). setpgrp Make the current process the leader of its process group. setregid Set the current process's real and effective group ids. setresgid Set the current process's real, effective, and saved group ids. setresuid Set the current process's real, effective, and saved user ids. setreuid Set the current process's real and effective user ids. setsid Call the system call setsid(). setuid Set the current process's user id. setxattr Set extended attribute attribute on path to value. SF_MNOWAIT Parameters to the sendfile() function, if the implementation supports them. SF_NOCACHE Parameter to the sendfile() function, if the implementation supports it. SF_NODISKIO Parameters to the sendfile() function, if the implementation supports them. SF_SYNC Parameters to the sendfile() function, if the implementation supports them. spawnl Execute file with arguments from args in a subprocess. spawnle Execute file with arguments from args in a subprocess with the supplied environment. spawnlp Execute file (which is looked for along $PATH) with arguments from args in a subprocess with the supplied environment. spawnlpe Execute file (which is looked for along $PATH) with arguments from args in a subprocess with the supplied environment. spawnv Execute file with arguments from args in a subprocess. spawnve Execute file with arguments from args in a subprocess with the specified environment. spawnvp Execute file (which is looked for along $PATH) with arguments from args in a subprocess. spawnvpe Execute file (which is looked for along $PATH) with arguments from args in a subprocess with the supplied environment. splice Transfer count bytes from one pipe to a descriptor or vice versa. ST_NODEV Disallow access to device special files. ST_NOSUID Setuid/setgid bits are disabled or not supported. ST_WRITE Write on file/directory/symlink. startfile Start a file with its associated application. stat Perform a stat system call on the given path. stat_result stat_result: Result from stat, fstat, or lstat. statvfs Perform a statvfs system call on the given path. statx Get the status of a file or file descriptor by performing a statx() system call on the given path. STATX_ATIME Bitflags for use in the mask parameter to os.statx(). STATX_BLOCKS Bitflags for use in the mask parameter to os.statx(). STATX_BTIME Bitflags for use in the mask parameter to os.statx(). STATX_CTIME Bitflags for use in the mask parameter to os.statx(). STATX_GID Bitflags for use in the mask parameter to os.statx(). STATX_INO Bitflags for use in the mask parameter to os.statx(). STATX_MNT_ID Bitflags for use in the mask parameter to os.statx(). STATX_MODE Bitflags for use in the mask parameter to os.statx(). STATX_MTIME Bitflags for use in the mask parameter to os.statx(). STATX_NLINK Bitflags for use in the mask parameter to os.statx(). statx_result Information about a file returned by os.statx(). STATX_SIZE Bitflags for use in the mask parameter to os.statx(). STATX_SUBVOL Bitflags for use in the mask parameter to os.statx(). STATX_TYPE Bitflags for use in the mask parameter to os.statx(). STATX_UID Bitflags for use in the mask parameter to os.statx(). strerror Translate an error code to a message string. supports_dir_fd A set object indicating which functions in the os module accept an open file descriptor for their dir_fd parameter. supports_effective_ids A set object indicating whether os.access() permits specifying True for its effective_ids parameter on the local platform. supports_fd A set object indicating which functions in the os module permit specifying their path parameter as an open file descriptor on the local platform. supports_follow_symlinks A set object indicating which functions in the os module accept False for their follow_symlinks parameter on the local platform. symlink Create a symbolic link pointing to src named dst. sync Force write of everything to disk. sysconf Return an integer-valued system configuration variable. sysconf_names Dictionary mapping names accepted by sysconf() to the integer values defined for those names by the host operating system. system Execute the command in a subshell. t tcgetpgrp Return the process group associated with the terminal specified by fd. tcsetpgrp Set the process group associated with the terminal specified by fd. terminal_size A tuple of (columns, lines) for holding terminal window size TFD_CLOEXEC A flag for the timerfd_create() function, If TFD_CLOEXEC is set as a flag, set close-on-exec flag for new file descriptor. TFD_NONBLOCK A flag for the timerfd_create() function, which sets the O_NONBLOCK status flag for the new timer file descriptor. TFD_TIMER_ABSTIME A flag for the timerfd_settime() and timerfd_settime_ns() functions. TFD_TIMER_CANCEL_ON_SET A flag for the timerfd_settime() and timerfd_settime_ns() functions along with TFD_TIMER_ABSTIME. timerfd_gettime Return a tuple of a timer file descriptor's (next expiration, interval) in float seconds. timerfd_gettime_ns Return a tuple of a timer file descriptor's (next expiration, interval) in nanoseconds. times Return a collection containing process timing information. truncate Truncate a file, specified by path, to a specific length. ttyname Return the name of the terminal device connected to 'fd'. u umask Set the current numeric umask and return the previous umask. uname Return an object identifying the current operating system. unlink Remove a file (same as remove()). unlockpt Unlock a pseudo-terminal master/slave pair. unshare Disassociate parts of a process (or thread) execution context. urandom Return a bytes object containing random bytes suitable for cryptographic use. utime Set the access and modified time of path. w W_OK Values to pass as the mode parameter of access() to test the existence, readability, writability and executability of path, respectively. wait Wait for completion of a child process. wait3 Wait for completion of a child process. wait4 Wait for completion of a specific child process. waitid Returns the result of waiting for a process or processes. waitpid Wait for completion of a given child process. walk Directory tree generator. WCONTINUED This options flag for waitpid(), wait3(), wait4(), and waitid() causes child processes to be reported if they have been continued from a job control stop since they were last reported. WCOREDUMP Return True if the process returning status was dumped to a core file. WEXITED This options flag for waitid() causes child processes that have terminated to be reported. WIFCONTINUED Return True if a particular process was continued from a job control stop. WIFEXITED Return True if the process returning status exited via the exit() system call. WIFSIGNALED Return True if the process returning status was terminated by a signal. WIFSTOPPED Return True if the process returning status was stopped. WNOHANG This options flag causes waitpid(), wait3(), wait4(), and waitid() to return right away if no child process status is available immediately. WNOWAIT This options flag causes waitid() to leave the child in a waitable state, so that a later wait*() call can be used to retrieve the child status information again. write Write a bytes object to a file descriptor. writev Iterate over buffers, and write the contents of each to a file descriptor. WSTOPPED This options flag for waitid() causes child processes that have been stopped by the delivery of a signal to be reported. WSTOPSIG Return the signal that stopped the process that provided the status value. WTERMSIG Return the signal that terminated the process that provided the status value. WUNTRACED This options flag for waitpid(), wait3(), and wait4() causes child processes to also be reported if they have been stopped but their current state has not been reported since they were stopped. x X_OK Values to pass as the mode parameter of access() to test the existence, readability, writability and executability of path, respectively. XATTR_CREATE This is a possible value for the flags argument in setxattr(). XATTR_REPLACE This is a possible value for the flags argument in setxattr(). XATTR_SIZE_MAX The maximum size the value of an extended attribute can be.
Python docs © Python Software Foundation · Examples CC0 ·
Source on GitHub · Not affiliated with the PSF