試圖寫的函數作出決定。例如之前讀取一個外殼命令的輸出:蟒呼叫外殼命令並檢查響應
6 def getCreds():
7 global access_key, secret_key, yourName
8 access_key = raw_input("Enter Access Key: ")
9 secret_key = raw_input("Enter Secret Key: ")
10 infoCorrect = raw_input('Is this information correct? (y or n)')
11 if infoCorrect.lower() == "yes" or infoCorrect.lower() =="y":
12 call (["./somecommand -u %s -p %s -flags" % (access_key, secret_key) + tfdir],shell=True)
13 else:
外殼命令的輸出或者是
"You have successfully logged in"
or
"you cannot log in"
所以我不知道正確的語法去:
if response = "You have successfully logged in" :
(some action)
elif:
(some action)
如何我讀的反應呢?
謝謝!
如果你經常這樣做,有便利包裝可用。其中之一:https://github.com/Chiel92/python-shellout(免責聲明:我寫的) –
@chowpay,你的問題解決了嗎? – Shasha99