【4】进程管理-4-python实现系统交互--sys

This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter

1、sys.argv

是一个list,包含所有的命令行参数.

 print "script name is", sys.argv[0] #

使用sys.argv[0]采集脚本名称,第一个参数为sys.argv[1]

2、sys.path

是一个list,指明所有查找module,package的路径。Python在import其它模块时,是从sys.path中搜索的。如果缺省的sys.path中没有含有自己的模块或包的路径,可以动态的加入(sys.path.apend)即可

3、sys.modules

是一个dictionary,表示系统中所有可用的module。当import一个模块时首先会在这个列表中查找是否已经加载了此模块,如果加载了则只是将模块的名字加入到正在调用import的模块的Local名字空间中

print sys.modules.keys()
['os.path', 'os', 'exceptions', '_ _main_ _', 'ntpath', 'strop', 'nt',
'sys', '_ _builtin_ _', 'site', 'signal', 'UserDict', 'string', 'stat']

4、使用sys模块查找内建模块

builtin_module_names 列表包含 Python 解释器中所有内建模块的名称

sys.builtin_module_names

5、sys.platform

得到运行的操作系统环境

6、sys.stdout sys.stdin sys.stderr

分别表示标准输入输出,错误输出的文件对象.

7、sys.stdin.readline()

从标准输入读一行 sys.stdout.write(“a”) 屏幕输出a

8、sys.exit(exit_code)

退出程序

报错

./plot.py: /bioinfo/web/Tools/GenoPrimeWeb/venv/bin/python^M: bad interpreter: No such file or directory

解决办法:

dos2unix plot.py

参考资料:

官网:https://docs.python.org/2/library/sys.html?highlight=sys#module-sys

http://www.cnblogs.com/qq78292959/archive/2013/05/17/3083961.html

http://www.cnblogs.com/lraa/p/3716709.html

药企,独角兽,苏州。团队长期招人,感兴趣的都可以发邮件聊聊:tiehan@sina.cn
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn