生活随笔
收集整理的這篇文章主要介紹了
系统工具
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、概念
二、系統模塊
命令行參數sys.argv
import sys
def add(a
,b
):return a
+b
a
,b
= 0,0
if sys
.argv
[1]:a
= int(sys
.argv
[1])
if sys
.argv
[2]:b
= int(sys
.argv
[2])
print(add
(a
,b
))
命令行鍵入
python ans.py 2 3
5
包括了運行的文件
print(sys.argv)
['ans.py', '2', '3']
CMD輸入
dir /b
顯示
.idea
1bubble.py
2find_number.py
3common_divisor_multiple.py
在python中調用dos命令
os.system形式
os
.system
('dir /b')
輸出
.idea
1bubble.py
2find_number.py
3common_divisor_multiple.py
os.popen(commond)返回一個對象
.read() # 返回字符串,.readlines()# 返回列表
os
.popen
('dir /b')
Out
[32]: <os
._wrap_close at
0x586bc18>
os
.popen
('dir /b').read
()
Out
[33]: '
.idea\n1bubble
.py\n2find_number
.py\n3common_divisor_multiple
.py\n
....
os
.popen
('dir /b').readlines
()
Out
[34]:
['.idea\n','1bubble.py\n','2find_number.py\n','3common_divisor_multiple.py\n',
三、sys模塊
四、標準流
五、os模塊
總結
以上是生活随笔為你收集整理的系统工具的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。