Python (fourth edition reading experience) (System Tools) (i)

Source: Internet
Author: User
Tags stdin

This chapter will explain the introduction of Python common system tools

Most system-level interfaces in Python are concentrated in two modules: SYS and OS

But some other standard modules are still part of this field.

Such as:

Common:

Glob for file name extension

Socket for network connection and interprocess communication

threading, _thread,queue for running and synchronizing concurrent threads

Time,timeit to get system time-related details

Subprocess,multiprocessing for starting and controlling parallel processes

Signal,select,shutil,tempfile for a variety of system-related tasks

Not common:

Pyserial a serial Port interface

Pexpect a class except system for control program building dialogues

Built-in functions:

Open File System interface, etc.

But in general, the SYS module and OS module are the core modules of the system tools.

The SYS module is primarily responsible for the components associated with the Python interpreter, while the OS module contains the variables and functions corresponding to the underlying operating system of Python

You can see what the SYS module and OS modules can export at any time:

Import Sys

Print (dir (SYS))

[' __displayhook__ ', ' __doc__ ', ' __excepthook__ ', ' __interactivehook__ ', ' __loader__ ', ' __name__ ', ' __package__ ', ' __ Spec__ ', ' __stderr__ ', ' __stdin__ ', ' __stdout__ ', ' _clear_type_cache ', ' _current_frames ', ' _debugmallocstats ', ' _ GetFrame ', ' _git ', ' _home ', ' _xoptions ', ' api_version ', ' argv ', ' base_exec_prefix ', ' base_prefix ', ' Builtin_module_ ' Names ', ' byteorder ', ' call_tracing ', ' callstats ', ' copyright ', ' displayhook ', ' dllhandle ', ' dont_write_bytecode ', ' exc ' _info ', ' excepthook ', ' exec_prefix ', ' executable ', ' exit ', ' flags ', ' float_info ', ' float_repr_style ', ' Get_coroutine_ ' Wrapper ', ' getallocatedblocks ', ' getcheckinterval ', ' getdefaultencoding ', ' getfilesystemencoding ', ' getprofile ', ' Getrecursionlimit ', ' getrefcount ', ' getsizeof ', ' getswitchinterval ', ' gettrace ', ' getwindowsversion ', ' hash_info ', ' Hexversion ', ' implementation ', ' int_info ', ' Intern ', ' is_finalizing ', ' maxsize ', ' maxunicode ', ' meta_path ', ' modules ', ' Path ', ' path_hooks ', ' path_importer_cache ', ' platform ', ' prefix ', ' set_Coroutine_wrapper ', ' setcheckinterval ', ' setprofile ', ' setrecursionlimit ', ' setswitchinterval ', ' settrace ', ' stderr ' , ' stdin ', ' stdout ', ' thread_info ', ' Version ', ' Version_info ', ' warnoptions ', ' winver ']

Import OS

Print (dir (OS))

[' F_ok ', ' mutablemapping ', ' o_append ', ' o_binary ', ' o_creat ', ' o_excl ', ' o_noinherit ', ' o_random ', ' o_rdonly ', ' O_rdwr ' , ' o_sequential ', ' o_short_lived ', ' o_temporary ', ' o_text ', ' o_trunc ', ' o_wronly ', ' P_detach ', ' p_nowait ', ' P_nowaito ', ' P_overlay ', ' p_wait ', ' r_ok ', ' seek_cur ', ' seek_end ', ' seek_set ', ' Tmp_max ', ' w_ok ', ' x_ok ', ' _dummydirentry ', ' _ Environ ', ' __all__ ', ' __builtins__ ', ' __cached__ ', ' __doc__ ', ' __file__ ', ' __loader__ ', ' __name__ ', ' __package__ ', ' __ Spec__ ', ' _dummy_scandir ', ' _execvpe ', ' _exists ', ' _exit ', ' _get_exports_list ', ' _putenv ', ' _unsetenv ', ' _wrap_close ', ' Abort ', ' access ', ' altsep ', ' chdir ', ' chmod ', ' close ', ' closerange ', ' cpu_count ', ' curdir ', ' defpath ', ' device_encoding ' ', ' devnull ', ' dup ', ' dup2 ', ' environ ', ' errno ', ' Error ', ' execl ', ' execle ', ' execlp ', ' execlpe ', ' execv ', ' execve ', ' exec VP ', ' execvpe ', ' extsep ', ' fdopen ', ' fsdecode ', ' fsencode ', ' fstat ', ' fsync ', ' ftruncate ', ' get_exec_path ', ' Get_handle_ Inheritable ', ' get_inheritable ', ' get_terminal_sIze ', ' getcwd ', ' getcwdb ', ' getenv ', ' getlogin ', ' getpid ', ' getppid ', ' isatty ', ' kill ', ' linesep ', ' link ', ' LISTDIR ', ' LSE Ek ', ' lstat ', ' makedirs ', ' mkdir ', ' name ', ' Open ', ' pardir ', ' path ', ' pathsep ', ' pipe ', ' popen ', ' putenv ', ' read ', ' Readli ' NK ', ' remove ', ' removedirs ', ' Rename ', ' Renames ', ' replace ', ' rmdir ', ' scandir ', ' Sep ', ' set_handle_inheritable ', ' set_ ' Inheritable ', ' spawnl ', ' Spawnle ', ' spawnv ', ' spawnve ', ' st ', ' startfile ', ' stat ', ' stat_float_times ', ' stat_result ', ' Statvfs_result ', ' strerror ', ' Supports_bytes_environ ', ' supports_dir_fd ', ' supports_effective_ids ', ' supports_fd ', ' Supports_follow_symlinks ', ' symlink ', ' sys ', ' system ', ' terminal_size ', ' Times ', ' times_result ', ' truncate ', ' umask ', ' Uname_result ', ' unlink ', ' urandom ', ' utime ', ' waitpid ', ' walk ', ' write '

Display the document string:

Import Sys

Print (sys.__doc__)

This module provides access to some objects used or maintained by the
Interpreter and to functions this interact strongly with the interpreter.

Dynamic objects:

ARGV-command line arguments; ARGV[0] is the script pathname if known
Path-module search path; PATH[0] is the script directory, Else '
Modules--Dictionary of Loaded modules

Displayhook--Called to show results in an interactive session
Excepthook--called to handle any uncaught exception other than Systemexit
To customize printing in an interactive session or to install a custom
Top-level exception handler, assign other functions to replace these.

stdin-Standard input file object; Used by input ()
STDOUT-standard output file object; Used by print ()
STDERR-standard Error object; Used for error messages
By assigning other file objects (or objects, behave like files)
To these, it's possible to redirect all of the interpreter ' s I/O.

Last_type--type of last uncaught exception
Last_value--Value of last uncaught exception
Last_traceback--Traceback of last uncaught exception
These three is only available in an interactive session after a
Traceback has been printed.

Static objects:

Builtin_module_names--tuple of module names built into this interpreter
Copyright--Copyright notice pertaining to this interpreter
Exec_prefix--Prefix used to find the Machine-specific Python Library
Executable--Absolute path of the executable binary of the Python interpreter
Float_info-a struct sequence with information about the float implementation.
Float_repr_style--string indicating the style of repr () output for floats
Hash_info-a struct sequence with information about the hash algorithm.
Hexversion--Version information encoded as a single integer
Implementation--Python implementation information.
Int_info-a struct sequence with information about the INT implementation.
MAXSIZE-the largest supported length of containers.
Maxunicode-The value of the largest Unicode code point
Platform--platform identifier
Prefix--prefix used to find the Python library
Thread_info-a struct sequence with information about the thread implementation.
Version-the version of this interpreter as a string
Version_info--version information as a named tuple
Dllhandle--[Windows only] integer handle of the Python DLL
Winver--[Windows only] version number of the Python DLL
__STDIN__-the original stdin; Don ' t touch!
__STDOUT__-the original stdout; Don ' t touch!
__STDERR__-the original stderr; Don ' t touch!
__displayhook__-the original displayhook; Don ' t touch!
__excepthook__-the original excepthook; Don ' t touch!

Functions:

Displayhook ()--Print an object to the screen, and save it in Builtins._
Excepthook ()--Print a exception and its Traceback to Sys.stderr
Exc_info ()--return thread-safe information on the current exception
exit ()--Exit the Interpreter by raising Systemexit
Getdlopenflags ()--returns flags to being used for Dlopen () calls
GetProfile ()--G ET the global profiling function
Getrefcount ()--Return the reference count for a object (plus one:-)
Getrecursio Nlimit ()--return the max recursion depth for the interpreter
Getsizeof ()--return the size of a object in bytes
Gettrace ()--Get the Global debug tracing function
Setcheckinterval ()--control how often the interpreter checks for Events
Setdlopenflags ()--set the flags to being used for Dlopen () calls
Setprofile ()--Set the global profiling func tion
Setrecursionlimit ()--Set the max recursion depth for the interpreter
Settrace ()--Set the global debug Traci ng function

or help (SYS) will explain in more detail

Python (fourth edition reading experience) (System Tools) (i)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.