doc_content
stringlengths
1
386k
doc_id
stringlengths
5
188
os.dup2(fd, fd2, inheritable=True) 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.
python.library.os#os.dup2
os.environ 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.
python.library.os#os.environ
os.environb 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.
python.library.os#os.environb
exception os.error An alias for the built-in OSError exception.
python.library.os#os.error
os.execl(path, arg0, arg1, ...) os.execle(path, arg0, arg1, ..., env) os.execlp(file, arg0, arg1, ...) os.execlpe(file, arg0, arg1, ..., env) os.execv(path, args) os.execve(path, args, env) os.execvp(file, args) os.execvpe(file, args, env) 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.
python.library.os#os.execl
os.execl(path, arg0, arg1, ...) os.execle(path, arg0, arg1, ..., env) os.execlp(file, arg0, arg1, ...) os.execlpe(file, arg0, arg1, ..., env) os.execv(path, args) os.execve(path, args, env) os.execvp(file, args) os.execvpe(file, args, env) 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.
python.library.os#os.execle
os.execl(path, arg0, arg1, ...) os.execle(path, arg0, arg1, ..., env) os.execlp(file, arg0, arg1, ...) os.execlpe(file, arg0, arg1, ..., env) os.execv(path, args) os.execve(path, args, env) os.execvp(file, args) os.execvpe(file, args, env) 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.
python.library.os#os.execlp
os.execl(path, arg0, arg1, ...) os.execle(path, arg0, arg1, ..., env) os.execlp(file, arg0, arg1, ...) os.execlpe(file, arg0, arg1, ..., env) os.execv(path, args) os.execve(path, args, env) os.execvp(file, args) os.execvpe(file, args, env) 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.
python.library.os#os.execlpe
os.execl(path, arg0, arg1, ...) os.execle(path, arg0, arg1, ..., env) os.execlp(file, arg0, arg1, ...) os.execlpe(file, arg0, arg1, ..., env) os.execv(path, args) os.execve(path, args, env) os.execvp(file, args) os.execvpe(file, args, env) 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.
python.library.os#os.execv
os.execl(path, arg0, arg1, ...) os.execle(path, arg0, arg1, ..., env) os.execlp(file, arg0, arg1, ...) os.execlpe(file, arg0, arg1, ..., env) os.execv(path, args) os.execve(path, args, env) os.execvp(file, args) os.execvpe(file, args, env) 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.
python.library.os#os.execve
os.execl(path, arg0, arg1, ...) os.execle(path, arg0, arg1, ..., env) os.execlp(file, arg0, arg1, ...) os.execlpe(file, arg0, arg1, ..., env) os.execv(path, args) os.execve(path, args, env) os.execvp(file, args) os.execvpe(file, args, env) 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.
python.library.os#os.execvp
os.execl(path, arg0, arg1, ...) os.execle(path, arg0, arg1, ..., env) os.execlp(file, arg0, arg1, ...) os.execlpe(file, arg0, arg1, ..., env) os.execv(path, args) os.execve(path, args, env) os.execvp(file, args) os.execvpe(file, args, env) 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.
python.library.os#os.execvpe
os.extsep The character which separates the base filename from the extension; for example, the '.' in os.py. Also available via os.path.
python.library.os#os.extsep
os.EX_CANTCREAT Exit code that means a user specified output file could not be created. Availability: Unix.
python.library.os#os.EX_CANTCREAT
os.EX_CONFIG Exit code that means that some kind of configuration error occurred. Availability: Unix.
python.library.os#os.EX_CONFIG
os.EX_DATAERR Exit code that means the input data was incorrect. Availability: Unix.
python.library.os#os.EX_DATAERR
os.EX_IOERR Exit code that means that an error occurred while doing I/O on some file. Availability: Unix.
python.library.os#os.EX_IOERR
os.EX_NOHOST Exit code that means a specified host did not exist. Availability: Unix.
python.library.os#os.EX_NOHOST
os.EX_NOINPUT Exit code that means an input file did not exist or was not readable. Availability: Unix.
python.library.os#os.EX_NOINPUT
os.EX_NOPERM Exit code that means that there were insufficient permissions to perform the operation (but not intended for file system problems). Availability: Unix.
python.library.os#os.EX_NOPERM
os.EX_NOTFOUND Exit code that means something like “an entry was not found”. Availability: Unix.
python.library.os#os.EX_NOTFOUND
os.EX_NOUSER Exit code that means a specified user did not exist. Availability: Unix.
python.library.os#os.EX_NOUSER
os.EX_OK Exit code that means no error occurred. Availability: Unix.
python.library.os#os.EX_OK
os.EX_OSERR Exit code that means an operating system error was detected, such as the inability to fork or create a pipe. Availability: Unix.
python.library.os#os.EX_OSERR
os.EX_OSFILE Exit code that means some system file did not exist, could not be opened, or had some other kind of error. Availability: Unix.
python.library.os#os.EX_OSFILE
os.EX_PROTOCOL Exit code that means that a protocol exchange was illegal, invalid, or not understood. Availability: Unix.
python.library.os#os.EX_PROTOCOL
os.EX_SOFTWARE Exit code that means an internal software error was detected. Availability: Unix.
python.library.os#os.EX_SOFTWARE
os.EX_TEMPFAIL 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.
python.library.os#os.EX_TEMPFAIL
os.EX_UNAVAILABLE Exit code that means that a required service is unavailable. Availability: Unix.
python.library.os#os.EX_UNAVAILABLE
os.EX_USAGE Exit code that means the command was used incorrectly, such as when the wrong number of arguments are given. Availability: Unix.
python.library.os#os.EX_USAGE
os.fchdir(fd) 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.
python.library.os#os.fchdir
os.fchmod(fd, mode) 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.
python.library.os#os.fchmod
os.fchown(fd, uid, gid) 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.
python.library.os#os.fchown
os.fdatasync(fd) 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.
python.library.os#os.fdatasync
os.fdopen(fd, *args, **kwargs) 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.
python.library.os#os.fdopen
os.fork() 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.
python.library.os#os.fork
os.forkpty() 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.
python.library.os#os.forkpty
os.fpathconf(fd, name) 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.
python.library.os#os.fpathconf
os.fsdecode(filename) 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.
python.library.os#os.fsdecode
os.fsencode(filename) 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.
python.library.os#os.fsencode
os.fspath(path) 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.
python.library.os#os.fspath
os.fstat(fd) 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.
python.library.os#os.fstat
os.fstatvfs(fd) 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.
python.library.os#os.fstatvfs
os.fsync(fd) 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.
python.library.os#os.fsync
os.ftruncate(fd, length) 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
python.library.os#os.ftruncate
os.fwalk(top='.', topdown=True, onerror=None, *, follow_symlinks=False, dir_fd=None) 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: import os for root, dirs, files, rootfd in os.fwalk('python/Lib/email'): print(root, "consumes", end="") print(sum([os.stat(name, dir_fd=rootfd).st_size for name in files]), end="") print("bytes in", len(files), "non-directory files") if 'CVS' in dirs: dirs.remove('CVS') # don't visit CVS directories In the next example, walking the tree bottom-up is essential: rmdir() doesn’t allow deleting a directory before the directory is empty: # Delete everything reachable from the directory named in "top", # assuming there are no symbolic links. # CAUTION: This is dangerous! For example, if top == '/', it # could delete all your disk files. import os for root, dirs, files, rootfd in os.fwalk(top, topdown=False): for name in files: os.unlink(name, dir_fd=rootfd) for name in dirs: os.rmdir(name, dir_fd=rootfd) 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.
python.library.os#os.fwalk
os.F_LOCK os.F_TLOCK os.F_ULOCK os.F_TEST Flags that specify what action lockf() will take. Availability: Unix. New in version 3.3.
python.library.os#os.F_LOCK
os.F_OK os.R_OK os.W_OK os.X_OK Values to pass as the mode parameter of access() to test the existence, readability, writability and executability of path, respectively.
python.library.os#os.F_OK
os.F_LOCK os.F_TLOCK os.F_ULOCK os.F_TEST Flags that specify what action lockf() will take. Availability: Unix. New in version 3.3.
python.library.os#os.F_TEST
os.F_LOCK os.F_TLOCK os.F_ULOCK os.F_TEST Flags that specify what action lockf() will take. Availability: Unix. New in version 3.3.
python.library.os#os.F_TLOCK
os.F_LOCK os.F_TLOCK os.F_ULOCK os.F_TEST Flags that specify what action lockf() will take. Availability: Unix. New in version 3.3.
python.library.os#os.F_ULOCK
os.getcwd() Return a string representing the current working directory.
python.library.os#os.getcwd
os.getcwdb() 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.
python.library.os#os.getcwdb
os.getegid() 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.
python.library.os#os.getegid
os.getenv(key, default=None) 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.
python.library.os#os.getenv
os.getenvb(key, default=None) 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.
python.library.os#os.getenvb
os.geteuid() Return the current process’s effective user id. Availability: Unix.
python.library.os#os.geteuid
os.getgid() Return the real group id of the current process. Availability: Unix.
python.library.os#os.getgid
os.getgrouplist(user, group) 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.
python.library.os#os.getgrouplist
os.getgroups() 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().
python.library.os#os.getgroups
os.getloadavg() 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.
python.library.os#os.getloadavg
os.getlogin() 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.
python.library.os#os.getlogin
os.getpgid(pid) 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.
python.library.os#os.getpgid
os.getpgrp() Return the id of the current process group. Availability: Unix.
python.library.os#os.getpgrp
os.getpid() Return the current process id.
python.library.os#os.getpid
os.getppid() 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.
python.library.os#os.getppid
os.getpriority(which, who) 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.
python.library.os#os.getpriority
os.getrandom(size, flags=0) 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.
python.library.os#os.getrandom
os.getresgid() Return a tuple (rgid, egid, sgid) denoting the current process’s real, effective, and saved group ids. Availability: Unix. New in version 3.2.
python.library.os#os.getresgid
os.getresuid() Return a tuple (ruid, euid, suid) denoting the current process’s real, effective, and saved user ids. Availability: Unix. New in version 3.2.
python.library.os#os.getresuid
os.getsid(pid) Call the system call getsid(). See the Unix manual for the semantics. Availability: Unix.
python.library.os#os.getsid
os.getuid() Return the current process’s real user id. Availability: Unix.
python.library.os#os.getuid
os.getxattr(path, attribute, *, follow_symlinks=True) 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.
python.library.os#os.getxattr
os.get_blocking(fd) 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.
python.library.os#os.get_blocking
os.get_exec_path(env=None) 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.
python.library.os#os.get_exec_path
os.get_handle_inheritable(handle) Get the “inheritable” flag of the specified handle (a boolean). Availability: Windows.
python.library.os#os.get_handle_inheritable
os.get_inheritable(fd) Get the “inheritable” flag of the specified file descriptor (a boolean).
python.library.os#os.get_inheritable
os.get_terminal_size(fd=STDOUT_FILENO) 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.
python.library.os#os.get_terminal_size
os.GRND_NONBLOCK By default, when reading from /dev/random, getrandom() blocks if no random bytes are available, and when reading from /dev/urandom, it blocks if the entropy pool has not yet been initialized. 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.
python.library.os#os.GRND_NONBLOCK
os.GRND_RANDOM 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.
python.library.os#os.GRND_RANDOM
os.initgroups(username, gid) 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.
python.library.os#os.initgroups
os.isatty(fd) Return True if the file descriptor fd is open and connected to a tty(-like) device, else False.
python.library.os#os.isatty
os.kill(pid, sig) 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.
python.library.os#os.kill
os.killpg(pgid, sig) Send the signal sig to the process group pgid. Raises an auditing event os.killpg with arguments pgid, sig. Availability: Unix.
python.library.os#os.killpg
os.lchflags(path, flags) 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.
python.library.os#os.lchflags
os.lchmod(path, mode) 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.
python.library.os#os.lchmod
os.lchown(path, uid, gid) 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.
python.library.os#os.lchown
os.linesep 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.
python.library.os#os.linesep
os.link(src, dst, *, src_dir_fd=None, dst_dir_fd=None, follow_symlinks=True) 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.
python.library.os#os.link
os.listdir(path='.') 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.
python.library.os#os.listdir
os.listxattr(path=None, *, follow_symlinks=True) 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.
python.library.os#os.listxattr
os.lockf(fd, cmd, len) 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.
python.library.os#os.lockf
os.lseek(fd, pos, how) 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.
python.library.os#os.lseek
os.lstat(path, *, dir_fd=None) 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().
python.library.os#os.lstat
os.major(device) Extract the device major number from a raw device number (usually the st_dev or st_rdev field from stat).
python.library.os#os.major
os.makedev(major, minor) Compose a raw device number from the major and minor device numbers.
python.library.os#os.makedev
os.makedirs(name, mode=0o777, exist_ok=False) 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.
python.library.os#os.makedirs
os.memfd_create(name[, flags=os.MFD_CLOEXEC]) 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.
python.library.os#os.memfd_create
os.MFD_CLOEXEC os.MFD_ALLOW_SEALING os.MFD_HUGETLB os.MFD_HUGE_SHIFT os.MFD_HUGE_MASK os.MFD_HUGE_64KB os.MFD_HUGE_512KB os.MFD_HUGE_1MB os.MFD_HUGE_2MB os.MFD_HUGE_8MB os.MFD_HUGE_16MB os.MFD_HUGE_32MB os.MFD_HUGE_256MB os.MFD_HUGE_512MB os.MFD_HUGE_1GB os.MFD_HUGE_2GB os.MFD_HUGE_16GB 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.
python.library.os#os.MFD_ALLOW_SEALING
os.MFD_CLOEXEC os.MFD_ALLOW_SEALING os.MFD_HUGETLB os.MFD_HUGE_SHIFT os.MFD_HUGE_MASK os.MFD_HUGE_64KB os.MFD_HUGE_512KB os.MFD_HUGE_1MB os.MFD_HUGE_2MB os.MFD_HUGE_8MB os.MFD_HUGE_16MB os.MFD_HUGE_32MB os.MFD_HUGE_256MB os.MFD_HUGE_512MB os.MFD_HUGE_1GB os.MFD_HUGE_2GB os.MFD_HUGE_16GB 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.
python.library.os#os.MFD_CLOEXEC