Generate a SIGABRT signal to the current process. On Unix, the default behavior is to produce a core dump; on Windows, the process immediately returns an exit code of 3. Be aware that calling this function will not call the Python signal handler registered for SIGABRT with signal.signal().


Use the real uid/gid to test for access to path. Note that most operations will use the effective uid/gid, therefore this routine can be used in a suid/sgid environment to test if the invoking user has the specified access to path. mode should be F_OK to test the existence of path, or it can be the inclusive OR of one or more of R_OK, W_OK, and X_OK to test permissions. Return True if access is allowed, False if not. See the Unix man page access(2) for more information.
This function can support specifying paths relative to directory descriptors and not following symlinks.
If effective_ids is True, access() will perform its access checks using the effective uid/gid instead of the real uid/gid. effective_ids may not be supported on your platform; you can check whether or not it is available using os.supports_effective_ids. If it is unavailable, using it will raise a NotImplementedError.
Note
Using access() to check if a user is authorized to e.g. open a file before actually doing so using open() creates a security hole, because the user might exploit the short time interval between checking and opening the file to manipulate it. It’s preferable to use EAFP techniques. For example:
is better written as:
Note
I/O operations may fail even when access() indicates that they would succeed, particularly for operations on network filesystems which may have permissions semantics beyond the usual POSIX permission-bit model.
Changed in version 3.3: Added the dir_fd, effective_ids, and follow_symlinks parameters.
Changed in version 3.6: Accepts a path-like object.


Add a path to the DLL search path.
This search path is used when resolving dependencies for imported extension modules (the module itself is resolved through sys.path), and also by ctypes.
Remove the directory by calling close() on the returned object or using it in a with statement.
See the Microsoft documentation for more information about how DLLs are loaded.
Raises an auditing event os.add_dll_directory with argument path.
Availability: Windows.
New in version 3.8: Previous versions of CPython would resolve DLLs using the default behavior for the current process. This led to inconsistencies, such as only sometimes searching PATH or the current working directory, and OS functions such as AddDllDirectory having no effect.
In 3.8, the two primary ways DLLs are loaded now explicitly override the process-wide behavior to ensure consistency. See the porting notes for information on updating libraries.


An alternative character used by the operating system to separate pathname components, or None if only one separator character exists. This is set to '/' on Windows systems where sep is a backslash. Also available via os.path.


Change the current working directory to path.
This function can support specifying a file descriptor. The descriptor must refer to an opened directory, not an open file.
This function can raise OSError and subclasses such as FileNotFoundError, PermissionError, and NotADirectoryError.
Raises an auditing event os.chdir with argument path.
New in version 3.3: Added support for specifying path as a file descriptor on some platforms.
Changed in version 3.6: Accepts a path-like object.


Set the flags of path to the numeric flags. flags may take a combination (bitwise OR) of the following values (as defined in the stat module):
This function can support not following symlinks.
Raises an auditing event os.chflags with arguments path, flags.
Availability: Unix.
New in version 3.3: The follow_symlinks argument.
Changed in version 3.6: Accepts a path-like object.


Change the mode of path to the numeric mode. mode may take one of the following values (as defined in the stat module) or bitwise ORed combinations of them:
This function can support specifying a file descriptor, paths relative to directory descriptors and not following symlinks.
Note
Although Windows supports chmod(), you can only set the file’s read-only flag with it (via the stat.S_IWRITE and stat.S_IREAD constants or a corresponding integer value). All other bits are ignored.
Raises an auditing event os.chmod with arguments path, mode, dir_fd.
New in version 3.3: Added support for specifying path as an open file descriptor, and the dir_fd and follow_symlinks arguments.
Changed in version 3.6: Accepts a path-like object.


Change the owner and group id of path to the numeric uid and gid. To leave one of the ids unchanged, set it to -1.
This function can support specifying a file descriptor, paths relative to directory descriptors and not following symlinks.
See shutil.chown() for a higher-level function that accepts names in addition to numeric ids.
Raises an auditing event os.chown with arguments path, uid, gid, dir_fd.
Availability: Unix.
New in version 3.3: Added support for specifying path as an open file descriptor, and the dir_fd and follow_symlinks arguments.
Changed in version 3.6: Supports a path-like object.


Change the root directory of the current process to path.
Availability: Unix.
Changed in version 3.6: Accepts a path-like object.


These are the possible values for si_code in the result returned by waitid().
Availability: Unix.
New in version 3.3.
Changed in version 3.9: Added CLD_KILLED and CLD_STOPPED values.


Close file descriptor fd.
Note
This function is intended for low-level I/O and must be applied to a file descriptor as returned by os.open() or pipe(). To close a “file object” returned by the built-in function open() or by popen() or fdopen(), use its close() method.


Close all file descriptors from fd_low (inclusive) to fd_high (exclusive), ignoring errors. Equivalent to (but much faster than):


Return string-valued system configuration values. name specifies the configuration value to retrieve; it may be a string which is the name of a defined system value; these names are specified in a number of standards (POSIX, Unix 95, Unix 98, and others). Some platforms define additional names as well. The names known to the host operating system are given as the keys of the confstr_names dictionary. For configuration variables not included in that mapping, passing an integer for name is also accepted.
If the configuration value specified by name isn’t defined, None is returned.
If name is a string and is not known, ValueError is raised. If a specific value for name is not supported by the host system, even if it is included in confstr_names, an OSError is raised with errno.EINVAL for the error number.
Availability: Unix.


Dictionary mapping names accepted by confstr() to the integer values defined for those names by the host operating system. This can be used to determine the set of names known to the system.
Availability: Unix.


Copy count bytes from file descriptor src, starting from offset offset_src, to file descriptor dst, starting from offset offset_dst. If offset_src is None, then src is read from the current position; respectively for offset_dst. The files pointed by src and dst must reside in the same filesystem, otherwise an OSError is raised with errno set to errno.EXDEV.
This copy is done without the additional cost of transferring data from the kernel to user space and then back into the kernel. Additionally, some filesystems could implement extra optimizations. The copy is done as if both files are opened as binary.
The return value is the amount of bytes copied. This could be less than the amount requested.
Availability: Linux kernel >= 4.5 or glibc >= 2.27.
New in version 3.8.


Return the number of CPUs in the system. Returns None if undetermined.
This number is not equivalent to the number of CPUs the current process can use. The number of usable CPUs can be obtained with len(os.sched_getaffinity(0))
New in version 3.4.


Return the filename corresponding to the controlling terminal of the process.
Availability: Unix.


The constant string used by the operating system to refer to the current directory. This is '.' for Windows and POSIX. Also available via os.path.


The default search path used by exec*p* and spawn*p* if the environment doesn’t have a 'PATH' key. Also available via os.path.


Return a string describing the encoding of the device associated with fd if it is connected to a terminal; else return None.


The file path of the null device. For example: '/dev/null' for POSIX, 'nul' for Windows. Also available via os.path.


Object yielded by scandir() to expose the file path and other file attributes of a directory entry.
scandir() will provide as much of this information as possible without making additional system calls. When a stat() or lstat() system call is made, the os.DirEntry object will cache the result.
os.DirEntry instances are not intended to be stored in long-lived data structures; if you know the file metadata has changed or if a long time has elapsed since calling scandir(), call os.stat(entry.path) to fetch up-to-date information.
Because the os.DirEntry methods can make operating system calls, they may also raise OSError. If you need very fine-grained control over errors, you can catch OSError when calling one of the os.DirEntry methods and handle as appropriate.
To be directly usable as a path-like object, os.DirEntry implements the PathLike interface.
Attributes and methods on a os.DirEntry instance are as follows:
The entry’s base filename, relative to the scandir() path argument.
The name attribute will be bytes if the scandir() path argument is of type bytes and str otherwise. Use fsdecode() to decode byte filenames.
The entry’s full path name: equivalent to os.path.join(scandir_path,
entry.name) where scandir_path is the scandir() path argument. The path is only absolute if the scandir() path argument was absolute. If the scandir() path argument was a file descriptor, the path attribute is the same as the name attribute.
The path attribute will be bytes if the scandir() path argument is of type bytes and str otherwise. Use fsdecode() to decode byte filenames.
Return the inode number of the entry.
The result is cached on the os.DirEntry object. Use os.stat(entry.path, follow_symlinks=False).st_ino to fetch up-to-date information.
On the first, uncached call, a system call is required on Windows but not on Unix.
Return True if this entry is a directory or a symbolic link pointing to a directory; return False if the entry is or points to any other kind of file, or if it doesn’t exist anymore.
If follow_symlinks is False, return True only if this entry is a directory (without following symlinks); return False if the entry is any other kind of file or if it doesn’t exist anymore.
The result is cached on the os.DirEntry object, with a separate cache for follow_symlinks True and False. Call os.stat() along with stat.S_ISDIR() to fetch up-to-date information.
On the first, uncached call, no system call is required in most cases. Specifically, for non-symlinks, neither Windows or Unix require a system call, except on certain Unix file systems, such as network file systems, that return dirent.d_type == DT_UNKNOWN. If the entry is a symlink, a system call will be required to follow the symlink unless follow_symlinks is False.
This method can raise OSError, such as PermissionError, but FileNotFoundError is caught and not raised.
Return True if this entry is a file or a symbolic link pointing to a file; return False if the entry is or points to a directory or other non-file entry, or if it doesn’t exist anymore.
If follow_symlinks is False, return True only if this entry is a file (without following symlinks); return False if the entry is a directory or other non-file entry, or if it doesn’t exist anymore.
The result is cached on the os.DirEntry object. Caching, system calls made, and exceptions raised are as per is_dir().
Return True if this entry is a symbolic link (even if broken); return False if the entry points to a directory or any kind of file, or if it doesn’t exist anymore.
The result is cached on the os.DirEntry object. Call os.path.islink() to fetch up-to-date information.
On the first, uncached call, no system call is required in most cases. Specifically, neither Windows or Unix require a system call, except on certain Unix file systems, such as network file systems, that return dirent.d_type == DT_UNKNOWN.
This method can raise OSError, such as PermissionError, but FileNotFoundError is caught and not raised.
Return a stat_result object for this entry. This method follows symbolic links by default; to stat a symbolic link add the follow_symlinks=False argument.
On Unix, this method always requires a system call. On Windows, it only requires a system call if follow_symlinks is True and the entry is a reparse point (for example, a symbolic link or directory junction).
On Windows, the st_ino, st_dev and st_nlink attributes of the stat_result are always set to zero. Call os.stat() to get these attributes.
The result is cached on the os.DirEntry object, with a separate cache for follow_symlinks True and False. Call os.stat() to fetch up-to-date information.
Note that there is a nice correspondence between several attributes and methods of os.DirEntry and of pathlib.Path. In particular, the name attribute has the same meaning, as do the is_dir(), is_file(), is_symlink() and stat() methods.
New in version 3.5.
Changed in version 3.6: Added support for the PathLike interface. Added support for bytes paths on Windows.


Return the inode number of the entry.
The result is cached on the os.DirEntry object. Use os.stat(entry.path, follow_symlinks=False).st_ino to fetch up-to-date information.
On the first, uncached call, a system call is required on Windows but not on Unix.


Return True if this entry is a directory or a symbolic link pointing to a directory; return False if the entry is or points to any other kind of file, or if it doesn’t exist anymore.
If follow_symlinks is False, return True only if this entry is a directory (without following symlinks); return False if the entry is any other kind of file or if it doesn’t exist anymore.
The result is cached on the os.DirEntry object, with a separate cache for follow_symlinks True and False. Call os.stat() along with stat.S_ISDIR() to fetch up-to-date information.
On the first, uncached call, no system call is required in most cases. Specifically, for non-symlinks, neither Windows or Unix require a system call, except on certain Unix file systems, such as network file systems, that return dirent.d_type == DT_UNKNOWN. If the entry is a symlink, a system call will be required to follow the symlink unless follow_symlinks is False.
This method can raise OSError, such as PermissionError, but FileNotFoundError is caught and not raised.


Return True if this entry is a file or a symbolic link pointing to a file; return False if the entry is or points to a directory or other non-file entry, or if it doesn’t exist anymore.
If follow_symlinks is False, return True only if this entry is a file (without following symlinks); return False if the entry is a directory or other non-file entry, or if it doesn’t exist anymore.
The result is cached on the os.DirEntry object. Caching, system calls made, and exceptions raised are as per is_dir().


Return True if this entry is a symbolic link (even if broken); return False if the entry points to a directory or any kind of file, or if it doesn’t exist anymore.
The result is cached on the os.DirEntry object. Call os.path.islink() to fetch up-to-date information.
On the first, uncached call, no system call is required in most cases. Specifically, neither Windows or Unix require a system call, except on certain Unix file systems, such as network file systems, that return dirent.d_type == DT_UNKNOWN.
This method can raise OSError, such as PermissionError, but FileNotFoundError is caught and not raised.


The entry’s base filename, relative to the scandir() path argument.
The name attribute will be bytes if the scandir() path argument is of type bytes and str otherwise. Use fsdecode() to decode byte filenames.


The entry’s full path name: equivalent to os.path.join(scandir_path,
entry.name) where scandir_path is the scandir() path argument. The path is only absolute if the scandir() path argument was absolute. If the scandir() path argument was a file descriptor, the path attribute is the same as the name attribute.
The path attribute will be bytes if the scandir() path argument is of type bytes and str otherwise. Use fsdecode() to decode byte filenames.


Return a stat_result object for this entry. This method follows symbolic links by default; to stat a symbolic link add the follow_symlinks=False argument.
On Unix, this method always requires a system call. On Windows, it only requires a system call if follow_symlinks is True and the entry is a reparse point (for example, a symbolic link or directory junction).
On Windows, the st_ino, st_dev and st_nlink attributes of the stat_result are always set to zero. Call os.stat() to get these attributes.
The result is cached on the os.DirEntry object, with a separate cache for follow_symlinks True and False. Call os.stat() to fetch up-to-date information.


Return a duplicate of file descriptor fd. The new file descriptor is non-inheritable.
On Windows, when duplicating a standard stream (0: stdin, 1: stdout, 2: stderr), the new file descriptor is inheritable.
Changed in version 3.4: The new file descriptor is now non-inheritable.


Duplicate file descriptor fd to fd2, closing the latter first if necessary. Return fd2. The new file descriptor is inheritable by default or non-inheritable if inheritable is False.
Changed in version 3.4: Add the optional inheritable parameter.
Changed in version 3.7: Return fd2 on success. Previously, None was always returned.


A mapping object representing the string environment. For example, environ['HOME'] is the pathname of your home directory (on some platforms), and is equivalent to getenv("HOME") in C.
This mapping is captured the first time the os module is imported, typically during Python startup as part of processing site.py. Changes to the environment made after this time are not reflected in os.environ, except for changes made by modifying os.environ directly.
This mapping may be used to modify the environment as well as query the environment. putenv() will be called automatically when the mapping is modified.
On Unix, keys and values use sys.getfilesystemencoding() and 'surrogateescape' error handler. Use environb if you would like to use a different encoding.
Note
Calling putenv() directly does not change os.environ, so it’s better to modify os.environ.
Note
On some platforms, including FreeBSD and Mac OS X, setting environ may cause memory leaks. Refer to the system documentation for putenv().
You can delete items in this mapping to unset environment variables. unsetenv() will be called automatically when an item is deleted from os.environ, and when one of the pop() or clear() methods is called.
Changed in version 3.9: Updated to support PEP 584’s merge (|) and update (|=) operators.


Bytes version of environ: a mapping object representing the environment as byte strings. environ and environb are synchronized (modify environb updates environ, and vice versa).
environb is only available if supports_bytes_environ is True.
New in version 3.2.
Changed in version 3.9: Updated to support PEP 584’s merge (|) and update (|=) operators.


An alias for the built-in OSError exception.


These functions all execute a new program, replacing the current process; they do not return. On Unix, the new executable is loaded into the current process, and will have the same process id as the caller. Errors will be reported as OSError exceptions.
The current process is replaced immediately. Open file objects and descriptors are not flushed, so if there may be data buffered on these open files, you should flush them using sys.stdout.flush() or os.fsync() before calling an exec* function.
The “l” and “v” variants of the exec* functions differ in how command-line arguments are passed. The “l” variants are perhaps the easiest to work with if the number of parameters is fixed when the code is written; the individual parameters simply become additional parameters to the execl*() functions. The “v” variants are good when the number of parameters is variable, with the arguments being passed in a list or tuple as the args parameter. In either case, the arguments to the child process should start with the name of the command being run, but this is not enforced.
The variants which include a “p” near the end (execlp(), execlpe(), execvp(), and execvpe()) will use the PATH environment variable to locate the program file. When the environment is being replaced (using one of the exec*e variants, discussed in the next paragraph), the new environment is used as the source of the PATH variable. The other variants, execl(), execle(), execv(), and execve(), will not use the PATH variable to locate the executable; path must contain an appropriate absolute or relative path.
For execle(), execlpe(), execve(), and execvpe() (note that these all end in “e”), the env parameter must be a mapping which is used to define the environment variables for the new process (these are used instead of the current process’ environment); the functions execl(), execlp(), execv(), and execvp() all cause the new process to inherit the environment of the current process.
For execve() on some platforms, path may also be specified as an open file descriptor. This functionality may not be supported on your platform; you can check whether or not it is available using os.supports_fd. If it is unavailable, using it will raise a NotImplementedError.
Raises an auditing event os.exec with arguments path, args, env.
Availability: Unix, Windows.
New in version 3.3: Added support for specifying path as an open file descriptor for execve().
Changed in version 3.6: Accepts a path-like object.


The character which separates the base filename from the extension; for example, the '.' in os.py. Also available via os.path.


Exit code that means a user specified output file could not be created.
Availability: Unix.


Exit code that means that some kind of configuration error occurred.
Availability: Unix.


Exit code that means the input data was incorrect.
Availability: Unix.


Exit code that means that an error occurred while doing I/O on some file.
Availability: Unix.


Exit code that means a specified host did not exist.
Availability: Unix.


Exit code that means an input file did not exist or was not readable.
Availability: Unix.


Exit code that means that there were insufficient permissions to perform the operation (but not intended for file system problems).
Availability: Unix.


Exit code that means something like “an entry was not found”.
Availability: Unix.


Exit code that means a specified user did not exist.
Availability: Unix.


Exit code that means no error occurred.
Availability: Unix.


Exit code that means an operating system error was detected, such as the inability to fork or create a pipe.
Availability: Unix.


Exit code that means some system file did not exist, could not be opened, or had some other kind of error.
Availability: Unix.


Exit code that means that a protocol exchange was illegal, invalid, or not understood.
Availability: Unix.


Exit code that means an internal software error was detected.
Availability: Unix.


Exit code that means a temporary failure occurred. This indicates something that may not really be an error, such as a network connection that couldn’t be made during a retryable operation.
Availability: Unix.


Exit code that means that a required service is unavailable.
Availability: Unix.


Exit code that means the command was used incorrectly, such as when the wrong number of arguments are given.
Availability: Unix.


Change the current working directory to the directory represented by the file descriptor fd. The descriptor must refer to an opened directory, not an open file. As of Python 3.3, this is equivalent to os.chdir(fd).
Raises an auditing event os.chdir with argument path.
Availability: Unix.


Change the mode of the file given by fd to the numeric mode. See the docs for chmod() for possible values of mode. As of Python 3.3, this is equivalent to os.chmod(fd, mode).
Raises an auditing event os.chmod with arguments path, mode, dir_fd.
Availability: Unix.


Change the owner and group id of the file given by fd to the numeric uid and gid. To leave one of the ids unchanged, set it to -1. See chown(). As of Python 3.3, this is equivalent to os.chown(fd, uid,
gid).
Raises an auditing event os.chown with arguments path, uid, gid, dir_fd.
Availability: Unix.


Force write of file with filedescriptor fd to disk. Does not force update of metadata.
Availability: Unix.
Note
This function is not available on MacOS.


Return an open file object connected to the file descriptor fd. This is an alias of the open() built-in function and accepts the same arguments. The only difference is that the first argument of fdopen() must always be an integer.


Fork a child process. Return 0 in the child and the child’s process id in the parent. If an error occurs OSError is raised.
Note that some platforms including FreeBSD <= 6.3 and Cygwin have known issues when using fork() from a thread.
Raises an auditing event os.fork with no arguments.
Changed in version 3.8: Calling fork() in a subinterpreter is no longer supported (RuntimeError is raised).
Warning
See ssl for applications that use the SSL module with fork().
Availability: Unix.


Fork a child process, using a new pseudo-terminal as the child’s controlling terminal. Return a pair of (pid, fd), where pid is 0 in the child, the new child’s process id in the parent, and fd is the file descriptor of the master end of the pseudo-terminal. For a more portable approach, use the pty module. If an error occurs OSError is raised.
Raises an auditing event os.forkpty with no arguments.
Changed in version 3.8: Calling forkpty() in a subinterpreter is no longer supported (RuntimeError is raised).
Availability: some flavors of Unix.


Return system configuration information relevant to an open file. name specifies the configuration value to retrieve; it may be a string which is the name of a defined system value; these names are specified in a number of standards (POSIX.1, Unix 95, Unix 98, and others). Some platforms define additional names as well. The names known to the host operating system are given in the pathconf_names dictionary. For configuration variables not included in that mapping, passing an integer for name is also accepted.
If name is a string and is not known, ValueError is raised. If a specific value for name is not supported by the host system, even if it is included in pathconf_names, an OSError is raised with errno.EINVAL for the error number.
As of Python 3.3, this is equivalent to os.pathconf(fd, name).
Availability: Unix.


Decode the path-like filename from the filesystem encoding with 'surrogateescape' error handler, or 'strict' on Windows; return str unchanged.
fsencode() is the reverse function.
New in version 3.2.
Changed in version 3.6: Support added to accept objects implementing the os.PathLike interface.


Encode path-like filename to the filesystem encoding with 'surrogateescape' error handler, or 'strict' on Windows; return bytes unchanged.
fsdecode() is the reverse function.
New in version 3.2.
Changed in version 3.6: Support added to accept objects implementing the os.PathLike interface.


Return the file system representation of the path.
If str or bytes is passed in, it is returned unchanged. Otherwise __fspath__() is called and its value is returned as long as it is a str or bytes object. In all other cases, TypeError is raised.
New in version 3.6.


Get the status of the file descriptor fd. Return a stat_result object.
As of Python 3.3, this is equivalent to os.stat(fd).
See also
The stat() function.


Return information about the filesystem containing the file associated with file descriptor fd, like statvfs(). As of Python 3.3, this is equivalent to os.statvfs(fd).
Availability: Unix.


Force write of file with filedescriptor fd to disk. On Unix, this calls the native fsync() function; on Windows, the MS _commit() function.
If you’re starting with a buffered Python file object f, first do f.flush(), and then do os.fsync(f.fileno()), to ensure that all internal buffers associated with f are written to disk.
Availability: Unix, Windows.


Truncate the file corresponding to file descriptor fd, so that it is at most length bytes in size. As of Python 3.3, this is equivalent to os.truncate(fd, length).
Raises an auditing event os.truncate with arguments fd, length.
Availability: Unix, Windows.
Changed in version 3.5: Added support for Windows


This behaves exactly like walk(), except that it yields a 4-tuple (dirpath, dirnames, filenames, dirfd), and it supports dir_fd.
dirpath, dirnames and filenames are identical to walk() output, and dirfd is a file descriptor referring to the directory dirpath.
This function always supports paths relative to directory descriptors and not following symlinks. Note however that, unlike other functions, the fwalk() default value for follow_symlinks is False.
Note
Since fwalk() yields file descriptors, those are only valid until the next iteration step, so you should duplicate them (e.g. with dup()) if you want to keep them longer.
This example displays the number of bytes taken by non-directory files in each directory under the starting directory, except that it doesn’t look under any CVS subdirectory:
In the next example, walking the tree bottom-up is essential: rmdir() doesn’t allow deleting a directory before the directory is empty:
Raises an auditing event os.fwalk with arguments top, topdown, onerror, follow_symlinks, dir_fd.
Availability: Unix.
New in version 3.3.
Changed in version 3.6: Accepts a path-like object.
Changed in version 3.7: Added support for bytes paths.


Flags that specify what action lockf() will take.
Availability: Unix.
New in version 3.3.


Values to pass as the mode parameter of access() to test the existence, readability, writability and executability of path, respectively.


Return a string representing the current working directory.


Return a bytestring representing the current working directory.
Changed in version 3.8: The function now uses the UTF-8 encoding on Windows, rather than the ANSI code page: see PEP 529 for the rationale. The function is no longer deprecated on Windows.


Return the effective group id of the current process. This corresponds to the “set id” bit on the file being executed in the current process.
Availability: Unix.


Return the value of the environment variable key if it exists, or default if it doesn’t. key, default and the result are str.
On Unix, keys and values are decoded with sys.getfilesystemencoding() and 'surrogateescape' error handler. Use os.getenvb() if you would like to use a different encoding.
Availability: most flavors of Unix, Windows.


Return the value of the environment variable key if it exists, or default if it doesn’t. key, default and the result are bytes.
getenvb() is only available if supports_bytes_environ is True.
Availability: most flavors of Unix.
New in version 3.2.


Return the current process’s effective user id.
Availability: Unix.


Return the real group id of the current process.
Availability: Unix.


Return list of group ids that user belongs to. If group is not in the list, it is included; typically, group is specified as the group ID field from the password record for user.
Availability: Unix.
New in version 3.3.


Return list of supplemental group ids associated with the current process.
Availability: Unix.
Note
On Mac OS X, getgroups() behavior differs somewhat from other Unix platforms. If the Python interpreter was built with a deployment target of 10.5 or earlier, getgroups() returns the list of effective group ids associated with the current user process; this list is limited to a system-defined number of entries, typically 16, and may be modified by calls to setgroups() if suitably privileged. If built with a deployment target greater than 10.5, getgroups() returns the current group access list for the user associated with the effective user id of the process; the group access list may change over the lifetime of the process, it is not affected by calls to setgroups(), and its length is not limited to 16. The deployment target value, MACOSX_DEPLOYMENT_TARGET, can be obtained with sysconfig.get_config_var().


Return the number of processes in the system run queue averaged over the last 1, 5, and 15 minutes or raises OSError if the load average was unobtainable.
Availability: Unix.


Return the name of the user logged in on the controlling terminal of the process. For most purposes, it is more useful to use getpass.getuser() since the latter checks the environment variables LOGNAME or USERNAME to find out who the user is, and falls back to pwd.getpwuid(os.getuid())[0] to get the login name of the current real user id.
Availability: Unix, Windows.


Return the process group id of the process with process id pid. If pid is 0, the process group id of the current process is returned.
Availability: Unix.


Return the id of the current process group.
Availability: Unix.


Return the parent’s process id. When the parent process has exited, on Unix the id returned is the one of the init process (1), on Windows it is still the same id, which may be already reused by another process.
Availability: Unix, Windows.
Changed in version 3.2: Added support for Windows.


Get program scheduling priority. The value which is one of PRIO_PROCESS, PRIO_PGRP, or PRIO_USER, and who is interpreted relative to which (a process identifier for PRIO_PROCESS, process group identifier for PRIO_PGRP, and a user ID for PRIO_USER). A zero value for who denotes (respectively) the calling process, the process group of the calling process, or the real user ID of the calling process.
Availability: Unix.
New in version 3.3.


Get up to size random bytes. The function can return less bytes than requested.
These bytes can be used to seed user-space random number generators or for cryptographic purposes.
getrandom() relies on entropy gathered from device drivers and other sources of environmental noise. Unnecessarily reading large quantities of data will have a negative impact on other users of the /dev/random and /dev/urandom devices.
The flags argument is a bit mask that can contain zero or more of the following values ORed together: os.GRND_RANDOM and GRND_NONBLOCK.
See also the Linux getrandom() manual page.
Availability: Linux 3.17 and newer.
New in version 3.6.


Return a tuple (rgid, egid, sgid) denoting the current process’s real, effective, and saved group ids.
Availability: Unix.
New in version 3.2.


Return a tuple (ruid, euid, suid) denoting the current process’s real, effective, and saved user ids.
Availability: Unix.
New in version 3.2.


Call the system call getsid(). See the Unix manual for the semantics.
Availability: Unix.


Return the current process’s real user id.
Availability: Unix.


Return the value of the extended filesystem attribute attribute for path. attribute can be bytes or str (directly or indirectly through the PathLike interface). If it is str, it is encoded with the filesystem encoding.
This function can support specifying a file descriptor and not following symlinks.
Raises an auditing event os.getxattr with arguments path, attribute.
Changed in version 3.6: Accepts a path-like object for path and attribute.


Get the blocking mode of the file descriptor: False if the O_NONBLOCK flag is set, True if the flag is cleared.
See also set_blocking() and socket.socket.setblocking().
Availability: Unix.
New in version 3.5.


Returns the list of directories that will be searched for a named executable, similar to a shell, when launching a process. env, when specified, should be an environment variable dictionary to lookup the PATH in. By default, when env is None, environ is used.
New in version 3.2.


Get the “inheritable” flag of the specified handle (a boolean).
Availability: Windows.


Get the “inheritable” flag of the specified file descriptor (a boolean).


Return the size of the terminal window as (columns, lines), tuple of type terminal_size.
The optional argument fd (default STDOUT_FILENO, or standard output) specifies which file descriptor should be queried.
If the file descriptor is not connected to a terminal, an OSError is raised.
shutil.get_terminal_size() is the high-level function which should normally be used, os.get_terminal_size is the low-level implementation.
Availability: Unix, Windows.


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.
If the GRND_NONBLOCK flag is set, then getrandom() does not block in these cases, but instead immediately raises BlockingIOError.
New in version 3.6.


If this bit is set, then random bytes are drawn from the /dev/random pool instead of the /dev/urandom pool.
New in version 3.6.


Call the system initgroups() to initialize the group access list with all of the groups of which the specified username is a member, plus the specified group id.
Availability: Unix.
New in version 3.2.


Return True if the file descriptor fd is open and connected to a tty(-like) device, else False.


Send signal sig to the process pid. Constants for the specific signals available on the host platform are defined in the signal module.
Windows: The signal.CTRL_C_EVENT and signal.CTRL_BREAK_EVENT signals are special signals which can only be sent to console processes which share a common console window, e.g., some subprocesses. Any other value for sig will cause the process to be unconditionally killed by the TerminateProcess API, and the exit code will be set to sig. The Windows version of kill() additionally takes process handles to be killed.
See also signal.pthread_kill().
Raises an auditing event os.kill with arguments pid, sig.
New in version 3.2: Windows support.


Send the signal sig to the process group pgid.
Raises an auditing event os.killpg with arguments pgid, sig.
Availability: Unix.


Set the flags of path to the numeric flags, like chflags(), but do not follow symbolic links. As of Python 3.3, this is equivalent to os.chflags(path, flags, follow_symlinks=False).
Raises an auditing event os.chflags with arguments path, flags.
Availability: Unix.
Changed in version 3.6: Accepts a path-like object.


Change the mode of path to the numeric mode. If path is a symlink, this affects the symlink rather than the target. See the docs for chmod() for possible values of mode. As of Python 3.3, this is equivalent to os.chmod(path, mode, follow_symlinks=False).
Raises an auditing event os.chmod with arguments path, mode, dir_fd.
Availability: Unix.
Changed in version 3.6: Accepts a path-like object.


Change the owner and group id of path to the numeric uid and gid. This function will not follow symbolic links. As of Python 3.3, this is equivalent to os.chown(path, uid, gid, follow_symlinks=False).
Raises an auditing event os.chown with arguments path, uid, gid, dir_fd.
Availability: Unix.
Changed in version 3.6: Accepts a path-like object.


The string used to separate (or, rather, terminate) lines on the current platform. This may be a single character, such as '\n' for POSIX, or multiple characters, for example, '\r\n' for Windows. Do not use os.linesep as a line terminator when writing files opened in text mode (the default); use a single '\n' instead, on all platforms.


Create a hard link pointing to src named dst.
This function can support specifying src_dir_fd and/or dst_dir_fd to supply paths relative to directory descriptors, and not following symlinks.
Raises an auditing event os.link with arguments src, dst, src_dir_fd, dst_dir_fd.
Availability: Unix, Windows.
Changed in version 3.2: Added Windows support.
New in version 3.3: Added the src_dir_fd, dst_dir_fd, and follow_symlinks arguments.
Changed in version 3.6: Accepts a path-like object for src and dst.


Return a list containing the names of the entries in the directory given by path. The list is in arbitrary order, and does not include the special entries '.' and '..' even if they are present in the directory. If a file is removed from or added to the directory during the call of this function, whether a name for that file be included is unspecified.
path may be a path-like object. If path is of type bytes (directly or indirectly through the PathLike interface), the filenames returned will also be of type bytes; in all other circumstances, they will be of type str.
This function can also support specifying a file descriptor; the file descriptor must refer to a directory.
Raises an auditing event os.listdir with argument path.
Note
To encode str filenames to bytes, use fsencode().
See also
The scandir() function returns directory entries along with file attribute information, giving better performance for many common use cases.
Changed in version 3.2: The path parameter became optional.
New in version 3.3: Added support for specifying path as an open file descriptor.
Changed in version 3.6: Accepts a path-like object.


Return a list of the extended filesystem attributes on path. The attributes in the list are represented as strings decoded with the filesystem encoding. If path is None, listxattr() will examine the current directory.
This function can support specifying a file descriptor and not following symlinks.
Raises an auditing event os.listxattr with argument path.
Changed in version 3.6: Accepts a path-like object.


Apply, test or remove a POSIX lock on an open file descriptor. fd is an open file descriptor. cmd specifies the command to use - one of F_LOCK, F_TLOCK, F_ULOCK or F_TEST. len specifies the section of the file to lock.
Raises an auditing event os.lockf with arguments fd, cmd, len.
Availability: Unix.
New in version 3.3.


Set the current position of file descriptor fd to position pos, modified by how: SEEK_SET or 0 to set the position relative to the beginning of the file; SEEK_CUR or 1 to set it relative to the current position; SEEK_END or 2 to set it relative to the end of the file. Return the new cursor position in bytes, starting from the beginning.


Perform the equivalent of an lstat() system call on the given path. Similar to stat(), but does not follow symbolic links. Return a stat_result object.
On platforms that do not support symbolic links, this is an alias for stat().
As of Python 3.3, this is equivalent to os.stat(path, dir_fd=dir_fd,
follow_symlinks=False).
This function can also support paths relative to directory descriptors.
See also
The stat() function.
Changed in version 3.2: Added support for Windows 6.0 (Vista) symbolic links.
Changed in version 3.3: Added the dir_fd parameter.
Changed in version 3.6: Accepts a path-like object.
Changed in version 3.8: On Windows, now opens reparse points that represent another path (name surrogates), including symbolic links and directory junctions. Other kinds of reparse points are resolved by the operating system as for stat().


Extract the device major number from a raw device number (usually the st_dev or st_rdev field from stat).


Compose a raw device number from the major and minor device numbers.


Recursive directory creation function. Like mkdir(), but makes all intermediate-level directories needed to contain the leaf directory.
The mode parameter is passed to mkdir() for creating the leaf directory; see the mkdir() description for how it is interpreted. To set the file permission bits of any newly-created parent directories you can set the umask before invoking makedirs(). The file permission bits of existing parent directories are not changed.
If exist_ok is False (the default), an FileExistsError is raised if the target directory already exists.
Note
makedirs() will become confused if the path elements to create include pardir (eg. “..” on UNIX systems).
This function handles UNC paths correctly.
Raises an auditing event os.mkdir with arguments path, mode, dir_fd.
New in version 3.2: The exist_ok parameter.
Changed in version 3.4.1: Before Python 3.4.1, if exist_ok was True and the directory existed, makedirs() would still raise an error if mode did not match the mode of the existing directory. Since this behavior was impossible to implement safely, it was removed in Python 3.4.1. See bpo-21082.
Changed in version 3.6: Accepts a path-like object.
Changed in version 3.7: The mode argument no longer affects the file permission bits of newly-created intermediate-level directories.


Create an anonymous file and return a file descriptor that refers to it. flags must be one of the os.MFD_* constants available on the system (or a bitwise ORed combination of them). By default, the new file descriptor is non-inheritable.
The name supplied in name is used as a filename and will be displayed as the target of the corresponding symbolic link in the directory /proc/self/fd/. The displayed name is always prefixed with memfd: and serves only for debugging purposes. Names do not affect the behavior of the file descriptor, and as such multiple files can have the same name without any side effects.
Availability: Linux 3.17 or newer with glibc 2.27 or newer.
New in version 3.8.


These flags can be passed to memfd_create().
Availability: Linux 3.17 or newer with glibc 2.27 or newer. The MFD_HUGE* flags are only available since Linux 4.14.
New in version 3.8.


Extract the device minor number from a raw device number (usually the st_dev or st_rdev field from stat).


Create a directory named path with numeric mode mode.
If the directory already exists, FileExistsError is raised.
On some systems, mode is ignored. Where it is used, the current umask value is first masked out. If bits other than the last 9 (i.e. the last 3 digits of the octal representation of the mode) are set, their meaning is platform-dependent. On some platforms, they are ignored and you should call chmod() explicitly to set them.
This function can also support paths relative to directory descriptors.
It is also possible to create temporary directories; see the tempfile module’s tempfile.mkdtemp() function.
Raises an auditing event os.mkdir with arguments path, mode, dir_fd.
New in version 3.3: The dir_fd argument.
Changed in version 3.6: Accepts a path-like object.


Create a FIFO (a named pipe) named path with numeric mode mode. The current umask value is first masked out from the mode.
This function can also support paths relative to directory descriptors.
FIFOs are pipes that can be accessed like regular files. FIFOs exist until they are deleted (for example with os.unlink()). Generally, FIFOs are used as rendezvous between “client” and “server” type processes: the server opens the FIFO for reading, and the client opens it for writing. Note that mkfifo() doesn’t open the FIFO — it just creates the rendezvous point.
Availability: Unix.
New in version 3.3: The dir_fd argument.
Changed in version 3.6: Accepts a path-like object.


Create a filesystem node (file, device special file or named pipe) named path. mode specifies both the permissions to use and the type of node to be created, being combined (bitwise OR) with one of stat.S_IFREG, stat.S_IFCHR, stat.S_IFBLK, and stat.S_IFIFO (those constants are available in stat). For stat.S_IFCHR and stat.S_IFBLK, device defines the newly created device special file (probably using os.makedev()), otherwise it is ignored.
This function can also support paths relative to directory descriptors.
Availability: Unix.
New in version 3.3: The dir_fd argument.
Changed in version 3.6: Accepts a path-like object.


The name of the operating system dependent module imported. The following names have currently been registered: 'posix', 'nt', 'java'.
See also
sys.platform has a finer granularity. os.uname() gives system-dependent version information.
The platform module provides detailed checks for the system’s identity.


Add increment to the process’s “niceness”. Return the new niceness.
Availability: Unix.


Open the file path and set various flags according to flags and possibly its mode according to mode. When computing mode, the current umask value is first masked out. Return the file descriptor for the newly opened file. The new file descriptor is non-inheritable.
For a description of the flag and mode values, see the C run-time documentation; flag constants (like O_RDONLY and O_WRONLY) are defined in the os module. In particular, on Windows adding O_BINARY is needed to open files in binary mode.
This function can support paths relative to directory descriptors with the dir_fd parameter.
Raises an auditing event open with arguments path, mode, flags.
Changed in version 3.4: The new file descriptor is now non-inheritable.
Note
This function is intended for low-level I/O. For normal usage, use the built-in function open(), which returns a file object with read() and write() methods (and many more). To wrap a file descriptor in a file object, use fdopen().
New in version 3.3: The dir_fd argument.
Changed in version 3.5: If the system call is interrupted and the signal handler does not raise an exception, the function now retries the system call instead of raising an InterruptedError exception (see PEP 475 for the rationale).
Changed in version 3.6: Accepts a path-like object.


Open a new pseudo-terminal pair. Return a pair of file descriptors (master, slave) for the pty and the tty, respectively. The new file descriptors are non-inheritable. For a (slightly) more portable approach, use the pty module.
Availability: some flavors of Unix.
Changed in version 3.4: The new file descriptors are now non-inheritable.


The above constants are available on Unix and Windows.


The above constants are extensions and not present if they are not defined by the C library.
Changed in version 3.4: Add O_PATH on systems that support it. Add O_TMPFILE, only available on Linux Kernel 3.11 or newer.


The above constants are only available on Windows.


The above constants are only available on Unix.
Changed in version 3.3: Add O_CLOEXEC constant.


The constant string used by the operating system to refer to the parent directory. This is '..' for Windows and POSIX. Also available via os.path.


Source code: Lib/posixpath.py (for POSIX) and Lib/ntpath.py (for Windows NT).
This module implements some useful functions on pathnames. To read or write files see open(), and for accessing the filesystem see the os module. The path parameters can be passed as either strings, or bytes. Applications are encouraged to represent file names as (Unicode) character strings. Unfortunately, some file names may not be representable as strings on Unix, so applications that need to support arbitrary file names on Unix should use bytes objects to represent path names. Vice versa, using bytes objects cannot represent all file names on Windows (in the standard mbcs encoding), hence Windows applications should use string objects to access all files.
Unlike a unix shell, Python does not do any automatic path expansions. Functions such as expanduser() and expandvars() can be invoked explicitly when an application desires shell-like path expansion. (See also the glob module.)
See also
The pathlib module offers high-level path objects.
Note
All of these functions accept either only bytes or only string objects as their parameters. The result is an object of the same type, if a path or file name is returned.
Note
Since different operating systems have different path name conventions, there are several versions of this module in the standard library. The os.path module is always the path module suitable for the operating system Python is running on, and therefore usable for local paths. However, you can also import and use the individual modules if you want to manipulate a path that is always in one of the different formats. They all have the same interface:
Changed in version 3.8: exists(), lexists(), isdir(), isfile(), islink(), and ismount() now return False instead of raising an exception for paths that contain characters or bytes unrepresentable at the OS level.
Return a normalized absolutized version of the pathname path. On most platforms, this is equivalent to calling the function normpath() as follows: normpath(join(os.getcwd(), path)).
Changed in version 3.6: Accepts a path-like object.
Return the base name of pathname path. This is the second element of the pair returned by passing path to the function split(). Note that the result of this function is different from the Unix basename program; where basename for '/foo/bar/' returns 'bar', the basename() function returns an empty string ('').
Changed in version 3.6: Accepts a path-like object.
Return the longest common sub-path of each pathname in the sequence paths. Raise ValueError if paths contain both absolute and relative pathnames, the paths are on the different drives or if paths is empty. Unlike commonprefix(), this returns a valid path.
Availability: Unix, Windows.
New in version 3.5.
Changed in version 3.6: Accepts a sequence of path-like objects.
Return the longest path prefix (taken character-by-character) that is a prefix of all paths in list. If list is empty, return the empty string ('').
Note
This function may return invalid paths because it works a character at a time. To obtain a valid path, see commonpath().
Changed in version 3.6: Accepts a path-like object.
Return the directory name of pathname path. This is the first element of the pair returned by passing path to the function split().
Changed in version 3.6: Accepts a path-like object.
Return True if path refers to an existing path or an open file descriptor. Returns False for broken symbolic links. On some platforms, this function may return False if permission is not granted to execute os.stat() on the requested file, even if the path physically exists.
Changed in version 3.3: path can now be an integer: True is returned if it is an open file descriptor, False otherwise.
Changed in version 3.6: Accepts a path-like object.
Return True if path refers to an existing path. Returns True for broken symbolic links. Equivalent to exists() on platforms lacking os.lstat().
Changed in version 3.6: Accepts a path-like object.
On Unix and Windows, return the argument with an initial component of ~ or ~user replaced by that user’s home directory.
On Unix, an initial ~ is replaced by the environment variable HOME if it is set; otherwise the current user’s home directory is looked up in the password directory through the built-in module pwd. An initial ~user is looked up directly in the password directory.
On Windows, USERPROFILE will be used if set, otherwise a combination of HOMEPATH and HOMEDRIVE will be used. An initial ~user is handled by stripping the last directory component from the created user path derived above.
If the expansion fails or if the path does not begin with a tilde, the path is returned unchanged.
Changed in version 3.6: Accepts a path-like object.
Changed in version 3.8: No longer uses HOME on Windows.
Return the argument with environment variables expanded. Substrings of the form $name or ${name} are replaced by the value of environment variable name. Malformed variable names and references to non-existing variables are left unchanged.
On Windows, %name% expansions are supported in addition to $name and ${name}.
Changed in version 3.6: Accepts a path-like object.
Return the time of last access of path. The return value is a floating point number giving the number of seconds since the epoch (see the time module). Raise OSError if the file does not exist or is inaccessible.
Return the time of last modification of path. The return value is a floating point number giving the number of seconds since the epoch (see the time module). Raise OSError if the file does not exist or is inaccessible.
Changed in version 3.6: Accepts a path-like object.
Return the system’s ctime which, on some systems (like Unix) is the time of the last metadata change, and, on others (like Windows), is the creation time for path. The return value is a number giving the number of seconds since the epoch (see the time module). Raise OSError if the file does not exist or is inaccessible.
Changed in version 3.6: Accepts a path-like object.
Return the size, in bytes, of path. Raise OSError if the file does not exist or is inaccessible.
Changed in version 3.6: Accepts a path-like object.
Return True if path is an absolute pathname. On Unix, that means it begins with a slash, on Windows that it begins with a (back)slash after chopping off a potential drive letter.
Changed in version 3.6: Accepts a path-like object.
Return True if path is an existing regular file. This follows symbolic links, so both islink() and isfile() can be true for the same path.
Changed in version 3.6: Accepts a path-like object.
Return True if path is an existing directory. This follows symbolic links, so both islink() and isdir() can be true for the same path.
Changed in version 3.6: Accepts a path-like object.
Return True if path refers to an existing directory entry that is a symbolic link. Always False if symbolic links are not supported by the Python runtime.
Changed in version 3.6: Accepts a path-like object.
Return True if pathname path is a mount point: a point in a file system where a different file system has been mounted. On POSIX, the function checks whether path’s parent, path/.., is on a different device than path, or whether path/.. and path point to the same i-node on the same device — this should detect mount points for all Unix and POSIX variants. It is not able to reliably detect bind mounts on the same filesystem. On Windows, a drive letter root and a share UNC are always mount points, and for any other path GetVolumePathName is called to see if it is different from the input path.
New in version 3.4: Support for detecting non-root mount points on Windows.
Changed in version 3.6: Accepts a path-like object.
Join one or more path components intelligently. The return value is the concatenation of path and any members of *paths with exactly one directory separator following each non-empty part except the last, meaning that the result will only end in a separator if the last part is empty. If a component is an absolute path, all previous components are thrown away and joining continues from the absolute path component.
On Windows, the drive letter is not reset when an absolute path component (e.g., r'\foo') is encountered. If a component contains a drive letter, all previous components are thrown away and the drive letter is reset. Note that since there is a current directory for each drive, os.path.join("c:", "foo") represents a path relative to the current directory on drive C: (c:foo), not c:\foo.
Changed in version 3.6: Accepts a path-like object for path and paths.
Normalize the case of a pathname. On Windows, convert all characters in the pathname to lowercase, and also convert forward slashes to backward slashes. On other operating systems, return the path unchanged.
Changed in version 3.6: Accepts a path-like object.
Normalize a pathname by collapsing redundant separators and up-level references so that A//B, A/B/, A/./B and A/foo/../B all become A/B. This string manipulation may change the meaning of a path that contains symbolic links. On Windows, it converts forward slashes to backward slashes. To normalize case, use normcase().
Changed in version 3.6: Accepts a path-like object.
Return the canonical path of the specified filename, eliminating any symbolic links encountered in the path (if they are supported by the operating system).
Note
When symbolic link cycles occur, the returned path will be one member of the cycle, but no guarantee is made about which member that will be.
Changed in version 3.6: Accepts a path-like object.
Changed in version 3.8: Symbolic links and junctions are now resolved on Windows.
Return a relative filepath to path either from the current directory or from an optional start directory. This is a path computation: the filesystem is not accessed to confirm the existence or nature of path or start. On Windows, ValueError is raised when path and start are on different drives.
start defaults to os.curdir.
Availability: Unix, Windows.
Changed in version 3.6: Accepts a path-like object.
Return True if both pathname arguments refer to the same file or directory. This is determined by the device number and i-node number and raises an exception if an os.stat() call on either pathname fails.
Availability: Unix, Windows.
Changed in version 3.2: Added Windows support.
Changed in version 3.4: Windows now uses the same implementation as all other platforms.
Changed in version 3.6: Accepts a path-like object.
Return True if the file descriptors fp1 and fp2 refer to the same file.
Availability: Unix, Windows.
Changed in version 3.2: Added Windows support.
Changed in version 3.6: Accepts a path-like object.
Return True if the stat tuples stat1 and stat2 refer to the same file. These structures may have been returned by os.fstat(), os.lstat(), or os.stat(). This function implements the underlying comparison used by samefile() and sameopenfile().
Availability: Unix, Windows.
Changed in version 3.4: Added Windows support.
Changed in version 3.6: Accepts a path-like object.
Split the pathname path into a pair, (head, tail) where tail is the last pathname component and head is everything leading up to that. The tail part will never contain a slash; if path ends in a slash, tail will be empty. If there is no slash in path, head will be empty. If path is empty, both head and tail are empty. Trailing slashes are stripped from head unless it is the root (one or more slashes only). In all cases, join(head, tail) returns a path to the same location as path (but the strings may differ). Also see the functions dirname() and basename().
Changed in version 3.6: Accepts a path-like object.
Split the pathname path into a pair (drive, tail) where drive is either a mount point or the empty string. On systems which do not use drive specifications, drive will always be the empty string. In all cases, drive
+ tail will be the same as path.
On Windows, splits a pathname into drive/UNC sharepoint and relative path.
If the path contains a drive letter, drive will contain everything up to and including the colon. e.g. splitdrive("c:/dir") returns ("c:", "/dir")
If the path contains a UNC path, drive will contain the host name and share, up to but not including the fourth separator. e.g. splitdrive("//host/computer/dir") returns ("//host/computer", "/dir")
Changed in version 3.6: Accepts a path-like object.
Split the pathname path into a pair (root, ext) such that root + ext ==
path, and ext is empty or begins with a period and contains at most one period. Leading periods on the basename are ignored; splitext('.cshrc') returns ('.cshrc', '').
Changed in version 3.6: Accepts a path-like object.
True if arbitrary Unicode strings can be used as file names (within limitations imposed by the file system).


Return a normalized absolutized version of the pathname path. On most platforms, this is equivalent to calling the function normpath() as follows: normpath(join(os.getcwd(), path)).
Changed in version 3.6: Accepts a path-like object.


Return the base name of pathname path. This is the second element of the pair returned by passing path to the function split(). Note that the result of this function is different from the Unix basename program; where basename for '/foo/bar/' returns 'bar', the basename() function returns an empty string ('').
Changed in version 3.6: Accepts a path-like object.


Return the longest common sub-path of each pathname in the sequence paths. Raise ValueError if paths contain both absolute and relative pathnames, the paths are on the different drives or if paths is empty. Unlike commonprefix(), this returns a valid path.
Availability: Unix, Windows.
New in version 3.5.
Changed in version 3.6: Accepts a sequence of path-like objects.


Return the longest path prefix (taken character-by-character) that is a prefix of all paths in list. If list is empty, return the empty string ('').
Note
This function may return invalid paths because it works a character at a time. To obtain a valid path, see commonpath().
Changed in version 3.6: Accepts a path-like object.


Return the directory name of pathname path. This is the first element of the pair returned by passing path to the function split().
Changed in version 3.6: Accepts a path-like object.


Return True if path refers to an existing path or an open file descriptor. Returns False for broken symbolic links. On some platforms, this function may return False if permission is not granted to execute os.stat() on the requested file, even if the path physically exists.
Changed in version 3.3: path can now be an integer: True is returned if it is an open file descriptor, False otherwise.
Changed in version 3.6: Accepts a path-like object.


On Unix and Windows, return the argument with an initial component of ~ or ~user replaced by that user’s home directory.
On Unix, an initial ~ is replaced by the environment variable HOME if it is set; otherwise the current user’s home directory is looked up in the password directory through the built-in module pwd. An initial ~user is looked up directly in the password directory.
On Windows, USERPROFILE will be used if set, otherwise a combination of HOMEPATH and HOMEDRIVE will be used. An initial ~user is handled by stripping the last directory component from the created user path derived above.
If the expansion fails or if the path does not begin with a tilde, the path is returned unchanged.
Changed in version 3.6: Accepts a path-like object.
Changed in version 3.8: No longer uses HOME on Windows.


Return the argument with environment variables expanded. Substrings of the form $name or ${name} are replaced by the value of environment variable name. Malformed variable names and references to non-existing variables are left unchanged.
On Windows, %name% expansions are supported in addition to $name and ${name}.
Changed in version 3.6: Accepts a path-like object.


Return the time of last access of path. The return value is a floating point number giving the number of seconds since the epoch (see the time module). Raise OSError if the file does not exist or is inaccessible.


Return the system’s ctime which, on some systems (like Unix) is the time of the last metadata change, and, on others (like Windows), is the creation time for path. The return value is a number giving the number of seconds since the epoch (see the time module). Raise OSError if the file does not exist or is inaccessible.
Changed in version 3.6: Accepts a path-like object.


Return the time of last modification of path. The return value is a floating point number giving the number of seconds since the epoch (see the time module). Raise OSError if the file does not exist or is inaccessible.
Changed in version 3.6: Accepts a path-like object.


Return the size, in bytes, of path. Raise OSError if the file does not exist or is inaccessible.
Changed in version 3.6: Accepts a path-like object.


Return True if path is an absolute pathname. On Unix, that means it begins with a slash, on Windows that it begins with a (back)slash after chopping off a potential drive letter.
Changed in version 3.6: Accepts a path-like object.


Return True if path is an existing directory. This follows symbolic links, so both islink() and isdir() can be true for the same path.
Changed in version 3.6: Accepts a path-like object.


Return True if path is an existing regular file. This follows symbolic links, so both islink() and isfile() can be true for the same path.
Changed in version 3.6: Accepts a path-like object.


Return True if path refers to an existing directory entry that is a symbolic link. Always False if symbolic links are not supported by the Python runtime.
Changed in version 3.6: Accepts a path-like object.


Return True if pathname path is a mount point: a point in a file system where a different file system has been mounted. On POSIX, the function checks whether path’s parent, path/.., is on a different device than path, or whether path/.. and path point to the same i-node on the same device — this should detect mount points for all Unix and POSIX variants. It is not able to reliably detect bind mounts on the same filesystem. On Windows, a drive letter root and a share UNC are always mount points, and for any other path GetVolumePathName is called to see if it is different from the input path.
New in version 3.4: Support for detecting non-root mount points on Windows.
Changed in version 3.6: Accepts a path-like object.


Join one or more path components intelligently. The return value is the concatenation of path and any members of *paths with exactly one directory separator following each non-empty part except the last, meaning that the result will only end in a separator if the last part is empty. If a component is an absolute path, all previous components are thrown away and joining continues from the absolute path component.
On Windows, the drive letter is not reset when an absolute path component (e.g., r'\foo') is encountered. If a component contains a drive letter, all previous components are thrown away and the drive letter is reset. Note that since there is a current directory for each drive, os.path.join("c:", "foo") represents a path relative to the current directory on drive C: (c:foo), not c:\foo.
Changed in version 3.6: Accepts a path-like object for path and paths.


Return True if path refers to an existing path. Returns True for broken symbolic links. Equivalent to exists() on platforms lacking os.lstat().
Changed in version 3.6: Accepts a path-like object.


Normalize the case of a pathname. On Windows, convert all characters in the pathname to lowercase, and also convert forward slashes to backward slashes. On other operating systems, return the path unchanged.
Changed in version 3.6: Accepts a path-like object.


Normalize a pathname by collapsing redundant separators and up-level references so that A//B, A/B/, A/./B and A/foo/../B all become A/B. This string manipulation may change the meaning of a path that contains symbolic links. On Windows, it converts forward slashes to backward slashes. To normalize case, use normcase().
Changed in version 3.6: Accepts a path-like object.


Return the canonical path of the specified filename, eliminating any symbolic links encountered in the path (if they are supported by the operating system).
Note
When symbolic link cycles occur, the returned path will be one member of the cycle, but no guarantee is made about which member that will be.
Changed in version 3.6: Accepts a path-like object.
Changed in version 3.8: Symbolic links and junctions are now resolved on Windows.


Return a relative filepath to path either from the current directory or from an optional start directory. This is a path computation: the filesystem is not accessed to confirm the existence or nature of path or start. On Windows, ValueError is raised when path and start are on different drives.
start defaults to os.curdir.
Availability: Unix, Windows.
Changed in version 3.6: Accepts a path-like object.


Return True if both pathname arguments refer to the same file or directory. This is determined by the device number and i-node number and raises an exception if an os.stat() call on either pathname fails.
Availability: Unix, Windows.
Changed in version 3.2: Added Windows support.
Changed in version 3.4: Windows now uses the same implementation as all other platforms.
Changed in version 3.6: Accepts a path-like object.


Return True if the file descriptors fp1 and fp2 refer to the same file.
Availability: Unix, Windows.
Changed in version 3.2: Added Windows support.
Changed in version 3.6: Accepts a path-like object.


Return True if the stat tuples stat1 and stat2 refer to the same file. These structures may have been returned by os.fstat(), os.lstat(), or os.stat(). This function implements the underlying comparison used by samefile() and sameopenfile().
Availability: Unix, Windows.
Changed in version 3.4: Added Windows support.
Changed in version 3.6: Accepts a path-like object.


Split the pathname path into a pair, (head, tail) where tail is the last pathname component and head is everything leading up to that. The tail part will never contain a slash; if path ends in a slash, tail will be empty. If there is no slash in path, head will be empty. If path is empty, both head and tail are empty. Trailing slashes are stripped from head unless it is the root (one or more slashes only). In all cases, join(head, tail) returns a path to the same location as path (but the strings may differ). Also see the functions dirname() and basename().
Changed in version 3.6: Accepts a path-like object.


Split the pathname path into a pair (drive, tail) where drive is either a mount point or the empty string. On systems which do not use drive specifications, drive will always be the empty string. In all cases, drive
+ tail will be the same as path.
On Windows, splits a pathname into drive/UNC sharepoint and relative path.
If the path contains a drive letter, drive will contain everything up to and including the colon. e.g. splitdrive("c:/dir") returns ("c:", "/dir")
If the path contains a UNC path, drive will contain the host name and share, up to but not including the fourth separator. e.g. splitdrive("//host/computer/dir") returns ("//host/computer", "/dir")
Changed in version 3.6: Accepts a path-like object.


Split the pathname path into a pair (root, ext) such that root + ext ==
path, and ext is empty or begins with a period and contains at most one period. Leading periods on the basename are ignored; splitext('.cshrc') returns ('.cshrc', '').
Changed in version 3.6: Accepts a path-like object.


True if arbitrary Unicode strings can be used as file names (within limitations imposed by the file system).


Return system configuration information relevant to a named file. name specifies the configuration value to retrieve; it may be a string which is the name of a defined system value; these names are specified in a number of standards (POSIX.1, Unix 95, Unix 98, and others). Some platforms define additional names as well. The names known to the host operating system are given in the pathconf_names dictionary. For configuration variables not included in that mapping, passing an integer for name is also accepted.
If name is a string and is not known, ValueError is raised. If a specific value for name is not supported by the host system, even if it is included in pathconf_names, an OSError is raised with errno.EINVAL for the error number.
This function can support specifying a file descriptor.
Availability: Unix.
Changed in version 3.6: Accepts a path-like object.


Dictionary mapping names accepted by pathconf() and fpathconf() to the integer values defined for those names by the host operating system. This can be used to determine the set of names known to the system.
Availability: Unix.


An abstract base class for objects representing a file system path, e.g. pathlib.PurePath.
New in version 3.6.
Return the file system path representation of the object.
The method should only return a str or bytes object, with the preference being for str.


Return the file system path representation of the object.
The method should only return a str or bytes object, with the preference being for str.


The character conventionally used by the operating system to separate search path components (as in PATH), such as ':' for POSIX or ';' for Windows. Also available via os.path.


Return a file descriptor referring to the process pid. This descriptor can be used to perform process management without races and signals. The flags argument is provided for future extensions; no flag values are currently defined.
See the pidfd_open(2) man page for more details.
Availability: Linux 5.3+
New in version 3.9.


Create a pipe. Return a pair of file descriptors (r, w) usable for reading and writing, respectively. The new file descriptor is non-inheritable.
Availability: Unix, Windows.
Changed in version 3.4: The new file descriptors are now non-inheritable.


Create a pipe with flags set atomically. flags can be constructed by ORing together one or more of these values: O_NONBLOCK, O_CLOEXEC. Return a pair of file descriptors (r, w) usable for reading and writing, respectively.
Availability: some flavors of Unix.
New in version 3.3.


Lock program segments into memory. The value of op (defined in <sys/lock.h>) determines which segments are locked.
Availability: Unix.


Open a pipe to or from command cmd. The return value is an open file object connected to the pipe, which can be read or written depending on whether mode is 'r' (default) or 'w'. The buffering argument has the same meaning as the corresponding argument to the built-in open() function. The returned file object reads or writes text strings rather than bytes.
The close method returns None if the subprocess exited successfully, or the subprocess’s return code if there was an error. On POSIX systems, if the return code is positive it represents the return value of the process left-shifted by one byte. If the return code is negative, the process was terminated by the signal given by the negated value of the return code. (For example, the return value might be - signal.SIGKILL if the subprocess was killed.) On Windows systems, the return value contains the signed integer return code from the child process.
On Unix, waitstatus_to_exitcode() can be used to convert the close method result (exit status) into an exit code if it is not None. On Windows, the close method result is directly the exit code (or None).
This is implemented using subprocess.Popen; see that class’s documentation for more powerful ways to manage and communicate with subprocesses.


Announces an intention to access data in a specific pattern thus allowing the kernel to make optimizations. The advice applies to the region of the file specified by fd starting at offset and continuing for len bytes. advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL, POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED or POSIX_FADV_DONTNEED.
Availability: Unix.
New in version 3.3.


Flags that can be used in advice in posix_fadvise() that specify the access pattern that is likely to be used.
Availability: Unix.
New in version 3.3.


Ensures that enough disk space is allocated for the file specified by fd starting from offset and continuing for len bytes.
Availability: Unix.
New in version 3.3.


Wraps the posix_spawn() C library API for use from Python.
Most users should use subprocess.run() instead of posix_spawn().
The positional-only arguments path, args, and env are similar to execve().
The path parameter is the path to the executable file. The path should contain a directory. Use posix_spawnp() to pass an executable file without directory.
The file_actions argument may be a sequence of tuples describing actions to take on specific file descriptors in the child process between the C library implementation’s fork() and exec() steps. The first item in each tuple must be one of the three type indicator listed below describing the remaining tuple elements:
(os.POSIX_SPAWN_OPEN, fd, path, flags, mode)
Performs os.dup2(os.open(path, flags, mode), fd).
(os.POSIX_SPAWN_CLOSE, fd)
Performs os.close(fd).
(os.POSIX_SPAWN_DUP2, fd, new_fd)
Performs os.dup2(fd, new_fd).
These tuples correspond to the C library posix_spawn_file_actions_addopen(), posix_spawn_file_actions_addclose(), and posix_spawn_file_actions_adddup2() API calls used to prepare for the posix_spawn() call itself.
The setpgroup argument will set the process group of the child to the value specified. If the value specified is 0, the child’s process group ID will be made the same as its process ID. If the value of setpgroup is not set, the child will inherit the parent’s process group ID. This argument corresponds to the C library POSIX_SPAWN_SETPGROUP flag.
If the resetids argument is True it will reset the effective UID and GID of the child to the real UID and GID of the parent process. If the argument is False, then the child retains the effective UID and GID of the parent. In either case, if the set-user-ID and set-group-ID permission bits are enabled on the executable file, their effect will override the setting of the effective UID and GID. This argument corresponds to the C library POSIX_SPAWN_RESETIDS flag.
If the setsid argument is True, it will create a new session ID for posix_spawn. setsid requires POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP flag. Otherwise, NotImplementedError is raised.
The setsigmask argument will set the signal mask to the signal set specified. If the parameter is not used, then the child inherits the parent’s signal mask. This argument corresponds to the C library POSIX_SPAWN_SETSIGMASK flag.
The sigdef argument will reset the disposition of all signals in the set specified. This argument corresponds to the C library POSIX_SPAWN_SETSIGDEF flag.
The scheduler argument must be a tuple containing the (optional) scheduler policy and an instance of sched_param with the scheduler parameters. A value of None in the place of the scheduler policy indicates that is not being provided. This argument is a combination of the C library POSIX_SPAWN_SETSCHEDPARAM and POSIX_SPAWN_SETSCHEDULER flags.
Raises an auditing event os.posix_spawn with arguments path, argv, env.
New in version 3.8.
Availability: Unix.


Wraps the posix_spawnp() C library API for use from Python.
Similar to posix_spawn() except that the system searches for the executable file in the list of directories specified by the PATH environment variable (in the same way as for execvp(3)).
Raises an auditing event os.posix_spawn with arguments path, argv, env.
New in version 3.8.
Availability: See posix_spawn() documentation.


(os.POSIX_SPAWN_CLOSE, fd)
Performs os.close(fd).


(os.POSIX_SPAWN_DUP2, fd, new_fd)
Performs os.dup2(fd, new_fd).


(os.POSIX_SPAWN_OPEN, fd, path, flags, mode)
Performs os.dup2(os.open(path, flags, mode), fd).


Read at most n bytes from file descriptor fd at a position of offset, leaving the file offset unchanged.
Return a bytestring containing the bytes read. If the end of the file referred to by fd has been reached, an empty bytes object is returned.
Availability: Unix.
New in version 3.3.


Read from a file descriptor fd at a position of offset into mutable bytes-like objects buffers, leaving the file offset unchanged. Transfer data into each buffer until it is full and then move on to the next buffer in the sequence to hold the rest of the data.
The flags argument contains a bitwise OR of zero or more of the following flags:
Return the total number of bytes actually read which can be less than the total capacity of all the objects.
The operating system may set a limit (sysconf() value 'SC_IOV_MAX') on the number of buffers that can be used.
Combine the functionality of os.readv() and os.pread().
Availability: Linux 2.6.30 and newer, FreeBSD 6.0 and newer, OpenBSD 2.7 and newer, AIX 7.1 and newer. Using flags requires Linux 4.6 or newer.
New in version 3.7.


Parameters for the getpriority() and setpriority() functions.
Availability: Unix.
New in version 3.3.


Set the environment variable named key to the string value. Such changes to the environment affect subprocesses started with os.system(), popen() or fork() and execv().
Assignments to items in os.environ are automatically translated into corresponding calls to putenv(); however, calls to putenv() don’t update os.environ, so it is actually preferable to assign to items of os.environ.
Note
On some platforms, including FreeBSD and Mac OS X, setting environ may cause memory leaks. Refer to the system documentation for putenv().
Raises an auditing event os.putenv with arguments key, value.
Changed in version 3.9: The function is now always available.


Write the bytestring in str to file descriptor fd at position of offset, leaving the file offset unchanged.
Return the number of bytes actually written.
Availability: Unix.
New in version 3.3.


Write the buffers contents to file descriptor fd at a offset offset, leaving the file offset unchanged. buffers must be a sequence of bytes-like objects. Buffers are processed in array order. Entire contents of the first buffer is written before proceeding to the second, and so on.
The flags argument contains a bitwise OR of zero or more of the following flags:
Return the total number of bytes actually written.
The operating system may set a limit (sysconf() value 'SC_IOV_MAX') on the number of buffers that can be used.
Combine the functionality of os.writev() and os.pwrite().
Availability: Linux 2.6.30 and newer, FreeBSD 6.0 and newer, OpenBSD 2.7 and newer, AIX 7.1 and newer. Using flags requires Linux 4.7 or newer.
New in version 3.7.


These are the possible values for idtype in waitid(). They affect how id is interpreted.
Availability: Unix.
New in version 3.3.


Possible values for the mode parameter to the spawn* family of functions. These are less portable than those listed above. P_DETACH is similar to P_NOWAIT, but the new process is detached from the console of the calling process. If P_OVERLAY is used, the current process will be replaced; the spawn* function will not return.
Availability: Windows.


Possible values for the mode parameter to the spawn* family of functions. If either of these values is given, the spawn*() functions will return as soon as the new process has been created, with the process id as the return value.
Availability: Unix, Windows.


This is a Linux-specific idtype that indicates that id is a file descriptor that refers to a process.
Availability: Linux 5.4+
New in version 3.9.


Possible value for the mode parameter to the spawn* family of functions. If this is given as mode, the spawn*() functions will not return until the new process has run to completion and will return the exit code of the process the run is successful, or -signal if a signal kills the process.
Availability: Unix, Windows.


Read at most n bytes from file descriptor fd.
Return a bytestring containing the bytes read. If the end of the file referred to by fd has been reached, an empty bytes object is returned.
Note
This function is intended for low-level I/O and must be applied to a file descriptor as returned by os.open() or pipe(). To read a “file object” returned by the built-in function open() or by popen() or fdopen(), or sys.stdin, use its read() or readline() methods.
Changed in version 3.5: If the system call is interrupted and the signal handler does not raise an exception, the function now retries the system call instead of raising an InterruptedError exception (see PEP 475 for the rationale).


Return a string representing the path to which the symbolic link points. The result may be either an absolute or relative pathname; if it is relative, it may be converted to an absolute pathname using os.path.join(os.path.dirname(path), result).
If the path is a string object (directly or indirectly through a PathLike interface), the result will also be a string object, and the call may raise a UnicodeDecodeError. If the path is a bytes object (direct or indirectly), the result will be a bytes object.
This function can also support paths relative to directory descriptors.
When trying to resolve a path that may contain links, use realpath() to properly handle recursion and platform differences.
Availability: Unix, Windows.
Changed in version 3.2: Added support for Windows 6.0 (Vista) symbolic links.
New in version 3.3: The dir_fd argument.
Changed in version 3.6: Accepts a path-like object on Unix.
Changed in version 3.8: Accepts a path-like object and a bytes object on Windows.
Changed in version 3.8: Added support for directory junctions, and changed to return the substitution path (which typically includes \\?\ prefix) rather than the optional “print name” field that was previously returned.


Read from a file descriptor fd into a number of mutable bytes-like objects buffers. Transfer data into each buffer until it is full and then move on to the next buffer in the sequence to hold the rest of the data.
Return the total number of bytes actually read which can be less than the total capacity of all the objects.
The operating system may set a limit (sysconf() value 'SC_IOV_MAX') on the number of buffers that can be used.
Availability: Unix.
New in version 3.3.


Register callables to be executed when a new child process is forked using os.fork() or similar process cloning APIs. The parameters are optional and keyword-only. Each specifies a different call point.
These calls are only made if control is expected to return to the Python interpreter. A typical subprocess launch will not trigger them as the child is not going to re-enter the interpreter.
Functions registered for execution before forking are called in reverse registration order. Functions registered for execution after forking (either in the parent or in the child) are called in registration order.
Note that fork() calls made by third-party C code may not call those functions, unless it explicitly calls PyOS_BeforeFork(), PyOS_AfterFork_Parent() and PyOS_AfterFork_Child().
There is no way to unregister a function.
Availability: Unix.
New in version 3.7.


Remove (delete) the file path. If path is a directory, an IsADirectoryError is raised. Use rmdir() to remove directories. If the file does not exist, a FileNotFoundError is raised.
This function can support paths relative to directory descriptors.
On Windows, attempting to remove a file that is in use causes an exception to be raised; on Unix, the directory entry is removed but the storage allocated to the file is not made available until the original file is no longer in use.
This function is semantically identical to unlink().
Raises an auditing event os.remove with arguments path, dir_fd.
New in version 3.3: The dir_fd argument.
Changed in version 3.6: Accepts a path-like object.


Remove directories recursively. Works like rmdir() except that, if the leaf directory is successfully removed, removedirs() tries to successively remove every parent directory mentioned in path until an error is raised (which is ignored, because it generally means that a parent directory is not empty). For example, os.removedirs('foo/bar/baz') will first remove the directory 'foo/bar/baz', and then remove 'foo/bar' and 'foo' if they are empty. Raises OSError if the leaf directory could not be successfully removed.
Raises an auditing event os.remove with arguments path, dir_fd.
Changed in version 3.6: Accepts a path-like object.


Removes the extended filesystem attribute attribute from path. attribute should be bytes or str (directly or indirectly through the PathLike interface). If it is a string, it is encoded with the filesystem encoding.
This function can support specifying a file descriptor and not following symlinks.
Raises an auditing event os.removexattr with arguments path, attribute.
Changed in version 3.6: Accepts a path-like object for path and attribute.


Rename the file or directory src to dst. If dst exists, the operation will fail with an OSError subclass in a number of cases:
On Windows, if dst exists a FileExistsError is always raised.
On Unix, if src is a file and dst is a directory or vice-versa, an IsADirectoryError or a NotADirectoryError will be raised respectively. If both are directories and dst is empty, dst will be silently replaced. If dst is a non-empty directory, an OSError is raised. If both are files, dst it will be replaced silently if the user has permission. The operation may fail on some Unix flavors if src and dst are on different filesystems. If successful, the renaming will be an atomic operation (this is a POSIX requirement).
This function can support specifying src_dir_fd and/or dst_dir_fd to supply paths relative to directory descriptors.
If you want cross-platform overwriting of the destination, use replace().
Raises an auditing event os.rename with arguments src, dst, src_dir_fd, dst_dir_fd.
New in version 3.3: The src_dir_fd and dst_dir_fd arguments.
Changed in version 3.6: Accepts a path-like object for src and dst.


Recursive directory or file renaming function. Works like rename(), except creation of any intermediate directories needed to make the new pathname good is attempted first. After the rename, directories corresponding to rightmost path segments of the old name will be pruned away using removedirs().
Note
This function can fail with the new directory structure made if you lack permissions needed to remove the leaf directory or file.
Raises an auditing event os.rename with arguments src, dst, src_dir_fd, dst_dir_fd.
Changed in version 3.6: Accepts a path-like object for old and new.


Rename the file or directory src to dst. If dst is a directory, OSError will be raised. If dst exists and is a file, it will be replaced silently if the user has permission. The operation may fail if src and dst are on different filesystems. If successful, the renaming will be an atomic operation (this is a POSIX requirement).
This function can support specifying src_dir_fd and/or dst_dir_fd to supply paths relative to directory descriptors.
Raises an auditing event os.rename with arguments src, dst, src_dir_fd, dst_dir_fd.
New in version 3.3.
Changed in version 3.6: Accepts a path-like object for src and dst.


Remove (delete) the directory path. If the directory does not exist or is not empty, an FileNotFoundError or an OSError is raised respectively. In order to remove whole directory trees, shutil.rmtree() can be used.
This function can support paths relative to directory descriptors.
Raises an auditing event os.rmdir with arguments path, dir_fd.
New in version 3.3: The dir_fd parameter.
Changed in version 3.6: Accepts a path-like object.


Flags for use with the setdlopenflags() and getdlopenflags() functions. See the Unix manual page dlopen(3) for what the different flags mean.
New in version 3.3.


Provide a per-write equivalent of the O_DSYNC open(2) flag. This flag effect applies only to the data range written by the system call.
Availability: Linux 4.7 and newer.
New in version 3.7.


High priority read/write. Allows block-based filesystems to use polling of the device, which provides lower latency, but may use additional resources.
Currently, on Linux, this feature is usable only on a file descriptor opened using the O_DIRECT flag.
Availability: Linux 4.6 and newer.
New in version 3.7.


Do not wait for data which is not immediately available. If this flag is specified, the system call will return instantly if it would have to read data from the backing storage or wait for a lock.
If some data was successfully read, it will return the number of bytes read. If no bytes were read, it will return -1 and set errno to errno.EAGAIN.
Availability: Linux 4.14 and newer.
New in version 3.7.


Provide a per-write equivalent of the O_SYNC open(2) flag. This flag effect applies only to the data range written by the system call.
Availability: Linux 4.7 and newer.
New in version 3.7.


Values to pass as the mode parameter of access() to test the existence, readability, writability and executability of path, respectively.


Return an iterator of os.DirEntry objects corresponding to the entries in the directory given by path. The entries are yielded in arbitrary order, and the special entries '.' and '..' are not included. If a file is removed from or added to the directory after creating the iterator, whether an entry for that file be included is unspecified.
Using scandir() instead of listdir() can significantly increase the performance of code that also needs file type or file attribute information, because os.DirEntry objects expose this information if the operating system provides it when scanning a directory. All os.DirEntry methods may perform a system call, but is_dir() and is_file() usually only require a system call for symbolic links; os.DirEntry.stat() always requires a system call on Unix but only requires one for symbolic links on Windows.
path may be a path-like object. If path is of type bytes (directly or indirectly through the PathLike interface), the type of the name and path attributes of each os.DirEntry will be bytes; in all other circumstances, they will be of type str.
This function can also support specifying a file descriptor; the file descriptor must refer to a directory.
Raises an auditing event os.scandir with argument path.
The scandir() iterator supports the context manager protocol and has the following method:
Close the iterator and free acquired resources.
This is called automatically when the iterator is exhausted or garbage collected, or when an error happens during iterating. However it is advisable to call it explicitly or use the with statement.
New in version 3.6.
The following example shows a simple use of scandir() to display all the files (excluding directories) in the given path that don’t start with '.'. The entry.is_file() call will generally not make an additional system call:
Note
On Unix-based systems, scandir() uses the system’s opendir() and readdir() functions. On Windows, it uses the Win32 FindFirstFileW and FindNextFileW functions.
New in version 3.5.
New in version 3.6: Added support for the context manager protocol and the close() method. If a scandir() iterator is neither exhausted nor explicitly closed a ResourceWarning will be emitted in its destructor.
The function accepts a path-like object.
Changed in version 3.7: Added support for file descriptors on Unix.


Close the iterator and free acquired resources.
This is called automatically when the iterator is exhausted or garbage collected, or when an error happens during iterating. However it is advisable to call it explicitly or use the with statement.
New in version 3.6.


Scheduling policy for CPU-intensive processes that tries to preserve interactivity on the rest of the computer.


Return the set of CPUs the process with PID pid (or the current process if zero) is restricted to.


Return the scheduling parameters as a sched_param instance for the process with PID pid. A pid of 0 means the calling process.


Return the scheduling policy for the process with PID pid. A pid of 0 means the calling process. The result is one of the scheduling policy constants above.


Get the maximum priority value for policy. policy is one of the scheduling policy constants above.


Get the minimum priority value for policy. policy is one of the scheduling policy constants above.


Scheduling policy for extremely low priority background tasks.


This class represents tunable scheduling parameters used in sched_setparam(), sched_setscheduler(), and sched_getparam(). It is immutable.
At the moment, there is only one possible parameter:
The scheduling priority for a scheduling policy.


The scheduling priority for a scheduling policy.


This flag can be OR’ed with any other scheduling policy. When a process with this flag set forks, its child’s scheduling policy and priority are reset to the default.


Return the round-robin quantum in seconds for the process with PID pid. A pid of 0 means the calling process.