15. Generic Operating System Services¶
The modules described in this chapter provide interfaces to operating system features that are available on (almost) all operating systems, such as files and a clock. The interfaces are generally modeled after the Unix or C interfaces, but they are available on most other systems as well. Here’s an overview:
- 15.1.
os— Miscellaneous operating system interfaceserrorname- 15.1.1. Process Parameters
environctermid()getegid()geteuid()getgid()getgroups()initgroups()getlogin()getpgid()getpgrp()getpid()getppid()getresuid()getresgid()getuid()getenv()putenv()setegid()seteuid()setgid()setgroups()setpgrp()setpgid()setregid()setresgid()setresuid()setreuid()getsid()setsid()setuid()strerror()umask()uname()unsetenv()
- 15.1.2. File Object Creation
- 15.1.3. File Descriptor Operations
- 15.1.4. Files and Directories
access()F_OKR_OKW_OKX_OKchdir()fchdir()getcwd()getcwdu()chflags()chroot()chmod()chown()lchflags()lchmod()lchown()link()listdir()lstat()mkfifo()mknod()major()minor()makedev()mkdir()makedirs()pathconf()pathconf_namesreadlink()remove()removedirs()rename()renames()rmdir()stat()stat_float_times()statvfs()symlink()tempnam()tmpnam()TMP_MAXunlink()utime()walk()
- 15.1.5. Process Management
abort()execl()execle()execlp()execlpe()execv()execve()execvp()execvpe()_exit()EX_OKEX_USAGEEX_DATAERREX_NOINPUTEX_NOUSEREX_NOHOSTEX_UNAVAILABLEEX_SOFTWAREEX_OSERREX_OSFILEEX_CANTCREATEX_IOERREX_TEMPFAILEX_PROTOCOLEX_NOPERMEX_CONFIGEX_NOTFOUNDfork()forkpty()kill()killpg()nice()plock()spawnl()spawnle()spawnlp()spawnlpe()spawnv()spawnve()spawnvp()spawnvpe()P_NOWAITP_NOWAITOP_WAITP_DETACHP_OVERLAYstartfile()system()times()wait()waitpid()wait3()wait4()WNOHANGWCONTINUEDWUNTRACEDWCOREDUMP()WIFCONTINUED()WIFSTOPPED()WIFSIGNALED()WIFEXITED()WEXITSTATUS()WSTOPSIG()WTERMSIG()
- 15.1.6. Miscellaneous System Information
- 15.1.7. Miscellaneous Functions
- 15.2.
io— Core tools for working with streams - 15.3.
time— Time access and conversions - 15.4.
argparse— Parser for command-line options, arguments and sub-commands- 15.4.1. Example
- 15.4.2. ArgumentParser objects
- 15.4.3. The add_argument() method
- 15.4.4. The parse_args() method
- 15.4.5. Other utilities
- 15.4.6. Upgrading optparse code
- 15.5.
optparse— Parser for command line options- 15.5.1. Background
- 15.5.2. Tutorial
- 15.5.3. Reference Guide
- 15.5.3.1. Creating the parser
- 15.5.3.2. Populating the parser
- 15.5.3.3. Defining options
- 15.5.3.4. Option attributes
- 15.5.3.5. Standard option actions
- 15.5.3.6. Standard option types
- 15.5.3.7. Parsing arguments
- 15.5.3.8. Querying and manipulating your option parser
- 15.5.3.9. Conflicts between options
- 15.5.3.10. Cleanup
- 15.5.3.11. Other methods
- 15.5.4. Option Callbacks
- 15.5.4.1. Defining a callback option
- 15.5.4.2. How callbacks are called
- 15.5.4.3. Raising errors in a callback
- 15.5.4.4. Callback example 1: trivial callback
- 15.5.4.5. Callback example 2: check option order
- 15.5.4.6. Callback example 3: check option order (generalized)
- 15.5.4.7. Callback example 4: check arbitrary condition
- 15.5.4.8. Callback example 5: fixed arguments
- 15.5.4.9. Callback example 6: variable arguments
- 15.5.5. Extending
optparse
- 15.6.
getopt— C-style parser for command line options - 15.7.
logging— Logging facility for Python- 15.7.1. Logger Objects
LoggerLogger.propagateLogger.setLevel()Logger.isEnabledFor()Logger.getEffectiveLevel()Logger.getChild()Logger.debug()Logger.info()Logger.warning()Logger.error()Logger.critical()Logger.log()Logger.exception()Logger.addFilter()Logger.removeFilter()Logger.filter()Logger.addHandler()Logger.removeHandler()Logger.findCaller()Logger.handle()Logger.makeRecord()
- 15.7.2. Logging Levels
- 15.7.3. Handler Objects
- 15.7.4. Formatter Objects
- 15.7.5. Filter Objects
- 15.7.6. LogRecord Objects
- 15.7.7. LogRecord attributes
- 15.7.8. LoggerAdapter Objects
- 15.7.9. Thread Safety
- 15.7.10. Module-Level Functions
- 15.7.11. Integration with the warnings module
- 15.7.1. Logger Objects
- 15.8.
logging.config— Logging configuration - 15.9.
logging.handlers— Logging handlers- 15.9.1. StreamHandler
- 15.9.2. FileHandler
- 15.9.3. NullHandler
- 15.9.4. WatchedFileHandler
- 15.9.5. RotatingFileHandler
- 15.9.6. TimedRotatingFileHandler
- 15.9.7. SocketHandler
- 15.9.8. DatagramHandler
- 15.9.9. SysLogHandler
- 15.9.10. NTEventLogHandler
- 15.9.11. SMTPHandler
- 15.9.12. MemoryHandler
- 15.9.13. HTTPHandler
- 15.10.
getpass— Portable password input - 15.11.
curses— Terminal handling for character-cell displays- 15.11.1. Functions
errorbaudrate()beep()can_change_color()cbreak()color_content()color_pair()curs_set()def_prog_mode()def_shell_mode()delay_output()doupdate()echo()endwin()erasechar()filter()flash()flushinp()getmouse()getsyx()getwin()has_colors()has_ic()has_il()has_key()halfdelay()init_color()init_pair()initscr()is_term_resized()isendwin()keyname()killchar()longname()meta()mouseinterval()mousemask()napms()newpad()newwin()nl()nocbreak()noecho()nonl()noqiflush()noraw()pair_content()pair_number()putp()qiflush()raw()reset_prog_mode()reset_shell_mode()resetty()resize_term()resizeterm()savetty()setsyx()setupterm()start_color()termattrs()termname()tigetflag()tigetnum()tigetstr()tparm()typeahead()unctrl()ungetch()ungetmouse()use_env()use_default_colors()wrapper()
- 15.11.2. Window Objects
window.addch()window.addnstr()window.addstr()window.attroff()window.attron()window.attrset()window.bkgd()window.bkgdset()window.border()window.box()window.chgat()window.clear()window.clearok()window.clrtobot()window.clrtoeol()window.cursyncup()window.delch()window.deleteln()window.derwin()window.echochar()window.enclose()window.erase()window.getbegyx()window.getbkgd()window.getch()window.getkey()window.getmaxyx()window.getparyx()window.getstr()window.getyx()window.hline()window.idcok()window.idlok()window.immedok()window.inch()window.insch()window.insdelln()window.insertln()window.insnstr()window.insstr()window.instr()window.is_linetouched()window.is_wintouched()window.keypad()window.leaveok()window.move()window.mvderwin()window.mvwin()window.nodelay()window.notimeout()window.noutrefresh()window.overlay()window.overwrite()window.putwin()window.redrawln()window.redrawwin()window.refresh()window.resize()window.scroll()window.scrollok()window.setscrreg()window.standend()window.standout()window.subpad()window.subwin()window.syncdown()window.syncok()window.syncup()window.timeout()window.touchline()window.touchwin()window.untouchwin()window.vline()
- 15.11.3. Constants
- 15.11.1. Functions
- 15.12.
curses.textpad— Text input widget for curses programs - 15.13.
curses.ascii— Utilities for ASCII characters - 15.14.
curses.panel— A panel stack extension for curses - 15.15.
platform— Access to underlying platform’s identifying data - 15.16.
errno— Standard errno system symbolserrorcodeEPERMENOENTESRCHEINTREIOENXIOE2BIGENOEXECEBADFECHILDEAGAINENOMEMEACCESEFAULTENOTBLKEBUSYEEXISTEXDEVENODEVENOTDIREISDIREINVALENFILEEMFILEENOTTYETXTBSYEFBIGENOSPCESPIPEEROFSEMLINKEPIPEEDOMERANGEEDEADLKENAMETOOLONGENOLCKENOSYSENOTEMPTYELOOPEWOULDBLOCKENOMSGEIDRMECHRNGEL2NSYNCEL3HLTEL3RSTELNRNGEUNATCHENOCSIEL2HLTEBADEEBADREXFULLENOANOEBADRQCEBADSLTEDEADLOCKEBFONTENOSTRENODATAETIMEENOSRENONETENOPKGEREMOTEENOLINKEADVESRMNTECOMMEPROTOEMULTIHOPEDOTDOTEBADMSGEOVERFLOWENOTUNIQEBADFDEREMCHGELIBACCELIBBADELIBSCNELIBMAXELIBEXECEILSEQERESTARTESTRPIPEEUSERSENOTSOCKEDESTADDRREQEMSGSIZEEPROTOTYPEENOPROTOOPTEPROTONOSUPPORTESOCKTNOSUPPORTEOPNOTSUPPEPFNOSUPPORTEAFNOSUPPORTEADDRINUSEEADDRNOTAVAILENETDOWNENETUNREACHENETRESETECONNABORTEDECONNRESETENOBUFSEISCONNENOTCONNESHUTDOWNETOOMANYREFSETIMEDOUTECONNREFUSEDEHOSTDOWNEHOSTUNREACHEALREADYEINPROGRESSESTALEEUCLEANENOTNAMENAVAILEISNAMEREMOTEIOEDQUOT
- 15.17.
ctypes— A foreign function library for Python- 15.17.1. ctypes tutorial
- 15.17.1.1. Loading dynamic link libraries
- 15.17.1.2. Accessing functions from loaded dlls
- 15.17.1.3. Calling functions
- 15.17.1.4. Fundamental data types
- 15.17.1.5. Calling functions, continued
- 15.17.1.6. Calling functions with your own custom data types
- 15.17.1.7. Specifying the required argument types (function prototypes)
- 15.17.1.8. Return types
- 15.17.1.9. Passing pointers (or: passing parameters by reference)
- 15.17.1.10. Structures and unions
- 15.17.1.11. Structure/union alignment and byte order
- 15.17.1.12. Bit fields in structures and unions
- 15.17.1.13. Arrays
- 15.17.1.14. Pointers
- 15.17.1.15. Type conversions
- 15.17.1.16. Incomplete Types
- 15.17.1.17. Callback functions
- 15.17.1.18. Accessing values exported from dlls
- 15.17.1.19. Surprises
- 15.17.1.20. Variable-sized data types
- 15.17.2. ctypes reference
- 15.17.2.1. Finding shared libraries
- 15.17.2.2. Loading shared libraries
- 15.17.2.3. Foreign functions
- 15.17.2.4. Function prototypes
- 15.17.2.5. Utility functions
addressof()alignment()byref()cast()create_string_buffer()create_unicode_buffer()DllCanUnloadNow()DllGetClassObject()find_library()find_msvcrt()FormatError()GetLastError()get_errno()get_last_error()memmove()memset()POINTER()pointer()resize()set_conversion_mode()set_errno()set_last_error()sizeof()string_at()WinError()wstring_at()
- 15.17.2.6. Data types
- 15.17.2.7. Fundamental data types
- 15.17.2.8. Structured data types
- 15.17.2.9. Arrays and pointers
- 15.17.1. ctypes tutorial
