這是我的問題。我正在嘗試使用思科設備並關閉信息。當我運行我的代碼時,print語句在輸出的底部添加一個新的行,其中有一個0。下面是代碼,隨後的砰砰CLI輸入輸出輸出:Python打印添加新行和0
C:\Python30>python PLINKSSHtest.py
Enter your username: josh
Password:
plink -pw nowayjose -ssh [email protected] "show run | inc hostname"
hostname net-R2
0 <------------MY ISSUE
C:\Python30>plink -pw nowayjose -ssh [email protected] "show run | inc hostname"
hostname net-R2
<------------WHAT I EXPECT
這裏是我的代碼:
def read_dev():
# Print statement here for debugging
print ("plink -pw " + password + " -ssh " + user + "@" + HOST + " " + command)
cur_dev = os.system("plink -pw " + password + " -ssh " + user + "@" + HOST + " " + command)
return(cur_dev)
HOST = None
user = input("Enter your username: ")
password = getpass.getpass()
command = '"show run | inc hostname"'
HOST = '1.1.1.1'
print (read_dev())
別使用Python 3.0,它只是一個「概念驗證」。獲取最新版本的Python 3.1。 – 2010-11-30 19:09:13
簡短回答:您正在打印`read_dev()`函數返回的值。函數調用並自行調用 – martineau 2010-11-30 20:13:16