piton

Cards (277)

  • os — Miscellaneous operating system interfaces
  • This module provides a portable way of using operating system dependent functionality
  • If you just want to read or write a file see open(), if you want to manipulate paths, see the os.path module, and if you want to read all the lines in all the files on the command line see the fileinput module
  • For creating temporary files and directories see the tempfile module, and for high-level file and directory handling see the shutil module
  • The design of all built-in operating system dependent modules of Python is such that as long as the same functionality is available, it uses the same interface
  • Extensions peculiar to a particular operating system are also available through the os module, but using them is of course a threat to portability
  • All functions accepting path or file names accept both bytes and string objects, and result in an object of the same type, if a path or file name is returned
  • On VxWorks, os.popen, os.fork, os.execv and os.spawn*p* are not supported
  • On WebAssembly platforms wasm32-emscripten and wasm32-wasi, large parts of the os module are not available or behave differently
  • API related to processes (e.g. fork(), execve()), signals (e.g. kill(), wait()), and resources (e.g. nice()) are not available on WebAssembly platforms
  • Functions like getuid() and getpid() are emulated or stubs on WebAssembly platforms
  • All functions in this module raise OSError (or subclasses thereof) in the case of invalid or inaccessible file names and paths, or other arguments that have the correct type, but are not accepted by the operating system
  • os.error
    An alias for the built-in OSError exception
  • os.name
    The name of the operating system dependent module imported. The following names have currently been registered: 'posix', 'nt', 'java'
  • os.uname() gives system-dependent version information
  • The platform module provides detailed checks for the system's identity
  • File Names, Command Line Arguments, and Environment Variables
    In Python, file names, command line arguments, and environment variables are represented using the string type. On some systems, decoding these strings to and from bytes is necessary before passing them to the operating system
  • Filesystem encoding and error handler

    Python uses the filesystem encoding and error handler to perform the conversion between strings and bytes for file names, command line arguments, and environment variables
  • The filesystem encoding must guarantee to successfully decode all bytes below 128. If the filesystem encoding fails to provide this guarantee, API functions can raise UnicodeError
  • Python UTF-8 Mode
    The Python UTF-8 Mode ignores the locale encoding and forces the usage of the UTF-8 encoding
  • The Python UTF-8 Mode is enabled if the LC_CTYPE locale is C or POSIX at Python startup
  • The Python UTF-8 Mode can be enabled or disabled using the -X utf8 command line option and the PYTHONUTF8 environment variable
  • The Python UTF-8 Mode can only be enabled at the Python startup. Its value can be read from sys.flags.utf8_mode
  • PEP 686 states that Python 3.15 will make Python UTF-8 Mode default
  • os.ctermid()

    Return the filename corresponding to the controlling terminal of the process
  • os.environ

    A mapping object where keys and values are strings that represent the process environment
  • Changes to the environment made after the os module is imported are not reflected in os.environ, except for changes made by modifying os.environ directly
  • Calling putenv() directly does not change os.environ, so it's better to modify os.environ
  • On some platforms, including FreeBSD and macOS, setting environ may cause memory leaks
  • os.environb
    Bytes version of environ: a mapping object where both keys and values are bytes objects representing the process environment
  • environb is only available if supports_bytes_environ is True
  • os.fsencode(filename)

    Encode path-like filename to the filesystem encoding and error handler; return bytes unchanged
  • os.fsdecode(filename)

    Decode the path-like filename from the filesystem encoding and error handler; return str unchanged
  • os.fspath(path)

    Return the file system representation of the path
  • os.PathLike
    An abstract base class for objects representing a file system path
  • os.getenv(key, default=None)

    Return the value of the environment variable key as a string if it exists, or default if it doesn't
  • os.getenvb(key, default=None)

    Return the value of the environment variable key as bytes if it exists, or default if it doesn't
  • 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
  • os.getegid()
    Return the effective group id of the current process
  • os.geteuid()

    Return the current process's effective user id