Python中大多数系统接口都集中在两个模块:sys和os.这么说有点过于简单化 还有一些其他的表转模块也属于这个领域他们包括:

glob 用于文件名的扩展

socket 用于网络连接和进程间通信(IPC)

threading,_threading,queue 用于运行和同步话并发线程

time,timeit 用于获取系统时间相关细节。

subprocess,multiprocessing 用于启动和控制并行进程

signal,select,shutil,tempfile 用于多种系统相关任务

还有诸如pySerial(一种串行端口接口),Pexpect(一个用于控制程序间对话的类Expect系统) 甚至TWisted(一种网络框架) 等等第三方扩展包也归入系统编程领域。另外 一些内置函数实际上也是系统接口 例如open函数 就是文件系统接口 但大体而言sys和os模块一起组成了pYthon内置系统工具的核心部分

从原则上讲 sys负责导出与python解释器本身相关的组件(如模块搜索路径) os则包含于python所在底层操作系统相对应的变量和函数 实践中这种区别并不总是这么明显(如sys包含了标准输入输出流) 但也可以说它们与操作系统模式有关

获取模块文档

学习用python来编写系统在很大程度上就是学习python的系统模块

例如我们要知道一个内置模块导出的所有东西 可以在库手册里阅读相关条目 也可以阅读它的源码 或者交互获取它的属性列表和文档字符串

我们导入ptyhon3.1sys模块 看一看它为我们提供了什么好东西

Microsoft Windows [版本 6.1.7601]

版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:\Users\Administrator.WIN-20160322KSZ>

C:\Users\Administrator.WIN-20160322KSZ>D:

D:\>dir

驱动器 D 中的卷是 软件

卷的序列号是 000F-9CF8

D:\ 的目录

2016/07/03 21:43 6,862,200 1.zip

2016/09/14 11:17 1,325,052 code_short.pcm

2016/08/21 13:20 24 config.ini

2016/06/19 01:52 2,558 day6.py

2016/10/16 19:43

2016/11/22 01:02

2016/03/21 19:45

2016/03/27 14:45

2016/11/28 23:09

2016/06/21 10:52

2016/05/15 19:16

2016/05/02 23:02

2004/07/03 09:48 139,264 psicon.dll

2004/10/24 09:19 1,112 psicon.reg

2016/06/25 22:31 198,296 pyexpat.pyd

2016/05/22 20:53

2016/06/25 22:31 42,136 python.exe

2016/06/25 22:31 52,376 python3.dll

2016/06/25 22:31 3,931,288 python35.dll

2016/06/25 22:31 2,257,578 python35.zip

2016/06/25 22:31 42,136 pythonw.exe

2016/06/25 22:31 17 pyvenv.cfg

2016/10/06 13:07

2016/11/22 15:10

2016/06/17 15:32

2016/06/25 22:31 26,264 select.pyd

2016/06/25 22:31 773,784 sqlite3.dll

2016/08/21 19:11

2016/06/25 22:31 871,576 unicodedata.pyd

2016/06/25 22:31 89,416 vcruntime140.dll

2016/02/12 13:16

2016/06/25 22:31 25,752 winsound.pyd

2016/06/17 22:45

2016/06/25 22:31 91,288 _bz2.pyd

2016/06/25 22:31 129,176 _ctypes.pyd

2016/06/25 22:31 321,176 _decimal.pyd

2016/06/25 22:31 199,832 _elementtree.pyd

2016/06/25 22:31 1,444,504 _hashlib.pyd

2016/06/25 22:31 152,728 _lzma.pyd

2016/06/25 22:31 38,552 _msi.pyd

2016/06/25 22:31 28,824 _multiprocessing.pyd

2016/06/25 22:31 41,112 _overlapped.pyd

2016/06/25 22:31 72,344 _socket.pyd

2016/06/25 22:31 78,488 _sqlite3.pyd

2016/06/25 22:31 2,044,056 _ssl.pyd

2016/09/11 22:38

2016/03/22 20:31

2016/03/22 22:15 466 软件 (D).lnk

31 个文件 21,283,375 字节

17 个目录 113,867,571,200 可用字节

D:\>python

Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AM

D64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import sys

>>> dir(sys)

['__displayhook__', '__doc__', '__excepthook__', '__interactivehook__', '__loade

r__', '__name__', '__package__', '__spec__', '__stderr__', '__stdin__', '__stdou

t__', '_clear_type_cache', '_current_frames', '_debugmallocstats', '_getframe',

'_home', '_mercurial', '_xoptions', 'api_version', 'argv', 'base_exec_prefix', '

base_prefix', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats',

'copyright', 'displayhook', 'dllhandle', 'dont_write_bytecode', 'exc_info', 'exc

epthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'float_rep

r_style', 'get_coroutine_wrapper', 'getallocatedblocks', 'getcheckinterval', 'ge

tdefaultencoding', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', '

getrefcount', 'getsizeof', 'getswitchinterval', 'gettrace', 'getwindowsversion',

'hash_info', 'hexversion', 'implementation', 'int_info', 'intern', 'is_finalizi

ng', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'pat

h_importer_cache', 'platform', 'prefix', 'ps1', 'ps2', 'set_coroutine_wrapper',

'setcheckinterval', 'setprofile', 'setrecursionlimit', 'setswitchinterval', 'set

trace', 'stderr', 'stdin', 'stdout', 'thread_info', 'version', 'version_info', '

warnoptions', 'winver']

>>>

dir函数会简单返回一个列表 其中包含了带属性队形的所有属性的字符串名称 这是一种在交互提示符下唤醒对模块的记忆便捷方式

例如dir函数结果中有version的存在 我们得一知道有一个sys.version

>>>sys.__doc__  内置模块的__doc__字符传:返回值如下

"This module provides access to some objects used or maintained by the\ninterpre

ter and to functions that interact strongly with the interpreter.\n\nDynamic obj

ects:\n\nargv -- command line arguments; argv[0] is the script pathname if known

\npath -- module search path; path[0] is the script directory, else ''\nmodules

-- dictionary of loaded modules\n\ndisplayhook -- called to show results in an i

nteractive session\nexcepthook -- called to handle any uncaught exception other

than SystemExit\n To customize printing in an interactive session or to install

a custom\n top-level exception handler, assign other functions to replace thes

e.\n\nstdin -- standard input file object; used by input()\nstdout -- standard o

utput file object; used by print()\nstderr -- standard error object; used for er

ror messages\n By assigning other file objects (or objects that behave like fil

es)\n to these, it is possible to redirect all of the interpreter's I/O.\n\nlas

t_type -- type of last uncaught exception\nlast_value -- value of last uncaught

exception\nlast_traceback -- traceback of last uncaught exception\n These three

are only available in an interactive session after a\n traceback has been prin

ted.\n\nStatic objects:\n\nbuiltin_module_names -- tuple of module names built i

nto this interpreter\ncopyright -- copyright notice pertaining to this interpret

er\nexec_prefix -- prefix used to find the machine-specific Python library\nexec

utable -- absolute path of the executable binary of the Python interpreter\nfloa

t_info -- a struct sequence with information about the float implementation.\nfl

oat_repr_style -- string indicating the style of repr() output for floats\nhash_

info -- a struct sequence with information about the hash algorithm.\nhexversion

-- version information encoded as a single integer\nimplementation -- Python im

plementation information.\nint_info -- a struct sequence with information about

the int implementation.\nmaxsize -- the largest supported length of containers.\

nmaxunicode -- the value of the largest Unicode code point\nplatform -- platform

identifier\nprefix -- prefix used to find the Python library\nthread_info -- a

struct sequence with information about the thread implementation.\nversion -- th

e version of this interpreter as a string\nversion_info -- version information a

s a named tuple\ndllhandle -- [Windows only] integer handle of the Python DLL\nw

inver -- [Windows only] version number of the Python DLL\n__stdin__ -- the origi

nal stdin; don't touch!\n__stdout__ -- the original stdout; don't touch!\n__stde

rr__ -- the original stderr; don't touch!\n__displayhook__ -- the original displ

ayhook; don't touch!\n__excepthook__ -- the original excepthook; don't touch!\n\

nFunctions:\n\ndisplayhook() -- print an object to the screen, and save it in bu

iltins._\nexcepthook() -- print an exception and its traceback to sys.stderr\nex

c_info() -- return thread-safe information about the current exception\nexit() -

- exit the interpreter by raising SystemExit\ngetdlopenflags() -- returns flags

to be used for dlopen() calls\ngetprofile() -- get the global profiling function

\ngetrefcount() -- return the reference count for an object (plus one :-)\ngetre

cursionlimit() -- return the max recursion depth for the interpreter\ngetsizeof(

) -- return the size of an object in bytes\ngettrace() -- get the global debug t

racing function\nsetcheckinterval() -- control how often the interpreter checks

for events\nsetdlopenflags() -- set the flags to be used for dlopen() calls\nset

profile() -- set the global profiling function\nsetrecursionlimit() -- set the m

ax recursion depth for the interpreter\nsettrace() -- set the global debug traci

ng function\n"

>>>

>>>pirnt(sys.__doc__)

该模块提供了对使用或维护的一些对象的访问

解释器和与解释器交互的功能。

print()内置函数会正确地解释换行符 遗憾的是本身并不完成页面滚动或分页显示 因此在某些平台上仍会出现令人不满意的显示效果 其他工具如内置help(函数) 则做的很好

>>> help(sys)

Help on built-in module sys:

NAME

sys

MODULE REFERENCE

https://docs.python.org/3.5/library\sys.html

The following documentation is automatically generated from the Python

source files. It may be incomplete, incorrect or include features that

are considered implementation detail and may vary between Python

implementations. When in doubt, consult the module reference at the

location listed above.

DESCRIPTION

This module provides access to some objects used or maintained by the

interpreter and to functions that 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

-- More --

help函数是PyDoc系统提供的接口之一 PyDoc系统是python自带的标准库代码 可将对象相关的文档 呈现为格式化后的形式 这种格式化可以是类似Unix里的手册页 便于帮助使用 也是翻阅相关书籍和手册之前的最后一招。

python中的帮助系统_python系统模块相关推荐

  1. python中import time用法_Python time模块的用法

    在实际应用中,经常需要得到一些时间信息,如得到某个事件发生的时间.某个资源的有效期限及某个时间是否是周末等. 在 Python 中,有一个系统自带的库 time,在该库中提供了对时间.日期进行操作的一 ...

  2. python中calendar怎么用_Python时间模块datetime、time、calendar的使用方法

    import time import datetime #两日期相减 d1 = datetime.datetime(2005, 2, 16) d2 = datetime.datetime(2004, ...

  3. python中的替换函数_python:替换模块类中的函数

    我试图替换类中定义的函数,以便在不更改实际代码的情况下修改其函数(如内部工作). 我以前从来没有这样做过,因此在更换它时遇到一些问题. 更改代码会让我访问python库中的包,这不是一个很好的选择. ...

  4. python中configparser详解_python ConfigParser模块详解

    功能介绍 在程序中使用配置文件来灵活的配置一些参数是一件很常见的事情,配置文件的解析并不复杂,在python里更是如此,在官方发布的库中就包含有做这件事情的库,那就是ConfigParser,这里简单 ...

  5. python中使用sys模板和logging模块获取行号和函数名的方法

    From: http://www.jb51.net/article/49026.htm 这篇文章主要介绍了python中使用sys模板和logging模块获取行号和函数名的方法,需要的朋友可以参考下 ...

  6. python中常见的漏洞_Python常见安全漏洞及修复方法集合!你所不会的这里都有!...

    [51CTO技术沙龙]10月27日,让我们共同探索AI场景化应用实现之道 --> 概述 编写安全的代码很困难,当你学习一门编程语言.一个模块或框架时,你会学习其使用方法.在考虑安全性时,你需要考 ...

  7. Python中import导入上一级目录模块及循环import问题的解决

    Python中import导入上一级目录模块及循环import问题的解决 参考文章: (1)Python中import导入上一级目录模块及循环import问题的解决 (2)https://www.cn ...

  8. Python中第三方的库(library)、模块(module),包(package)的安装方法以及ImportError: No module named...

    Python中,想要安装第三方安装包,即third library,package等,对于熟悉的人来说,很简单. 但是对于新手,至少对于之前的我,很难,往往只是安装一个很小的包,都被搞得一头雾水. 现 ...

  9. python中pass的用法_python学习之getpass模块使用

    我们登入linux时,输入密码是什么都不显示的,在python中也可以这样做,那就是getpass模块(在pycharm中无法使用) getpass模块中包含几个比较实用的功能: 1.getpass ...

最新文章

  1. LeetCode 10. Regular Expression Matching python特性、动态规划、递归
  2. java 内存测试_请你说一下java jvm的内存机制
  3. vsftp认证之pam_mysql
  4. TCP/IP详解--第六章
  5. Web Deployment Projects with Visual Studio 2005
  6. SharePoint2016如何使用策略进行文档归档
  7. 我在河南安阳拍摄的一个山村小孩儿
  8. 豪横C4D电商实用素材,从此横着走
  9. 3.1 测试能否对标准输入设置偏移量
  10. 阶段1 语言基础+高级_1-3-Java语言高级_08-JDK8新特性_第1节 常用函数接口_16_常用的函数式接口_Function接口中练习-自定义函数模型拼接...
  11. 【转载好文】对char *和char []做形参的深入理解+const char*/char const*/char *const的解析
  12. 使用PoEdit翻译PO文件(转贴)
  13. 2018二月安恒月赛WRITE UP
  14. orcad的瞬态分析
  15. Spring学习笔记(一)
  16. ruoyi框架默认的导出Excel功能代码简析
  17. Windows变慢原因分析及解决方法
  18. 如何使用 vimdiff 来 git diff
  19. 长白山项目开发小组,day1
  20. 学软件测试最好的几本书,这8本书能帮你很多

热门文章

  1. linux下读写ntfs硬盘吗,Linux环境下实现NTFS分区完全读写的方法
  2. 大恒相机标定with MATLAB
  3. 微信小程序为啥有的时候不显示封面广告、以及其他广告
  4. 无缘中兴(拒绝了offer)
  5. 搜狗大数据总监、Polarr 联合创始人关于深度学习的分享交流 | 架构师小组交流会...
  6. 国考省考结构化面试:组织管理题,调研题,宣传题,活动题,整治题
  7. js-09二级联动购物车案例
  8. 第8周编程题在线测试
  9. 第十二届全国大学生信息安全竞赛-RE部分WP(目前前两题,待更)
  10. 第八-九周-总结(day38-54)