人生苦短我用python 初窥自动化运维sys模块

人生苦短我用python

初窥自动化运维sys模块

sys.argv

返回列表第一个元素为该文件

之后的元素为执行时的所加参数

#!/usr/bin/python36
# -*- coding: utf-8 -*-
# @Time    : 2018-09-07 16:20
# @Author  : FrancisDrakeK
# @Site    :
# @File    : E.py
# @Software: PyCharm
import sys
print(sys.argv)

 

 

 

sys.path 

返回系统的导入路径

#!/usr/bin/python36
# -*- coding: utf-8 -*-
# @Time    : 2018-09-07 16:20
# @Author  : FrancisDrakeK
# @Site    :
# @File    : E.py
# @Software: PyCharm
import sys
print(sys.path)

 

 

sys.exit

 

退出运行

#!/usr/bin/python36
# -*- coding: utf-8 -*-
# @Time    : 2018-09-07 16:20
# @Author  : FrancisDrakeK
# @Site    :
# @File    : E.py
# @Software: PyCharm
import sys
print(sys.path)
sys.exit()
print(sys.path)

 


#!/usr/bin/python36
# -*- coding: utf-8 -*-
# @Time    : 2018-09-07 16:20
# @Author  : FrancisDrakeK
# @Site    :
# @File    : E.py
# @Software: PyCharm
import sys
print(sys.path)
print(sys.path)

 


 

sys.stdout

标准输出 输出,但是不换行

#!/usr/bin/python36
# -*- coding: utf-8 -*-
# @Time    : 2018-09-07 16:20
# @Author  : FrancisDrakeK
# @Site    :
# @File    : E.py
# @Software: PyCharm
import sys
for i in range(10):
    print(str(i))
for j in range(10):
    sys.stdout.write(str(j))

 

在Python中print()就是调用sys.stdout 输出但是输出后换行

sys.stdin

标准输入

#!/usr/bin/python36
# -*- coding: utf-8 -*-
# @Time    : 2018-09-07 16:20
# @Author  : FrancisDrakeK
# @Site    :
# @File    : E.py
# @Software: PyCharm
import sys
sys.stdin
a=input('>>>')
print(a)

 





posted @ 2018-09-17 20:59  Francis_Drake_K  阅读(219)  评论(0编辑  收藏  举报