I understand from Python's documentation that I can check conditions with the format:
if x < 0:
else:
print('Else code')
I want to run a command and check whether that command is successful, but I get a "SyntaxError: invalid syntax" error. Help!
My format is roughly:
if myCommand(parameters):
print("It worked")
else:
print("It failed")
if mySecondCommand(parameters):
print("2nd command worked")
else:
print("2nd command failed")
And here's my actual code using the Netmiko library:
from netmiko import ConnectHandler
if net_connect = ConnectHandler(device_type='cisco_ios', ip='11.22.33.44', username='domain.login', password='DomainPassword'):
print("Domain login succeeded.")
else:
print("Domain login failed.")
if net_connect = ConnectHandler(device_type='cisco_ios', ip='11.22.33.44', username='StandardUsername', password='StandardPassword'):
print("Standard login worked")
else:
print("Standard login failed")
The output I get is:
if net_connect = ConnectHandler(device_type='cisco_ios', ip='11.22.33.444', username='domain.login', password='DomainPassword'):
^
SyntaxError: invalid syntax
Aucun commentaire:
Enregistrer un commentaire