標準庫sys模塊
官方文檔:https://docs.python.org/3/library/sys.html
(1)stdin
從標準輸入讀入數據
import sys
text = sys.stdin.read()
words = text.split("-")
for i in words:
print(i)
要得到返回結果,需要按 CTRL+D
才能返回。
因爲 read讀取數據 ctrl+d
是結束輸入 ,read並不會像input那樣遇到回車就返回讀取的數據
它會緩存。
text = input("")
for i in text:
print(i)
(2)argv
獲取程序外部向程序傳遞的參數
import sys
print(sys.argv[0])
print(sys.argv[1])
對比一下bash shell:
#!/bin/bash
echo "number:$#"
echo "scname:$0"
echo