Python 2.7 如何在python中将ipaddress作为输入
执行此操作时,它会给我一个错误:Python 2.7 如何在python中将ipaddress作为输入,python-2.7,os.system,Python 2.7,Os.system,执行此操作时,它会给我一个错误: Traceback (most recent call last): File "C:\Users\ibrahim\Desktop\app.py", line 23, in <module> a=input("enter the ipaddress") File "<string>", line 1 192.168.1.1 ^ SyntaxError: i
Traceback (most recent call last):
File "C:\Users\ibrahim\Desktop\app.py", line 23, in <module>
a=input("enter the ipaddress")
File "<string>", line 1
192.168.1.1
^
SyntaxError: invalid syntax
您正在传递字符串“a”,而不是变量
a
,请去掉引号:
import os
a=input("enter the ipaddress")
os.system(a)
我建议使用
hostname
而不是a
,因为您将在ssh后对某些设备运行一些命令,因此输入应该被分配为hostname
-ssh.connect(主机名,端口=22,用户名=x,密码=y)
。因此,建议的守则是—
import os
hostname=input("enter the ipaddress")
os.system(hostname)
回溯(最近一次调用):文件“C:\Users\ibrahim\Desktop\app.py”,第22行,在z=input(“”)文件“”第1行192.168.1.1^语法错误:无效语法
import os
hostname=input("enter the ipaddress")
os.system(hostname)