在python3中,我想在一行中打印一个包含几个变量的字符串。代码如下:
#!/usr/bin/env python3
import sys, socket, getpass
from netmiko import ConnectHandler
def sshHost(hostname):
username = input("Username: ")
password = getpass.getpass()
hostIp = socket.gethostbyname(hostname)
sshSession = ConnectHandler(device_type='juniper', ip=hostIp, username=username, password=password)
versionHostname = sshSession.send_command("show version | match Hostname:")
print('ssh session established with {}: {}'.format(versionHostname, hostIp), end="")
return sshSession
sshHost(sys.argv[1])
当功能打印时,输出位于3个不同的行上:
ssh session established with
Hostname: srx00.sw11.lab
: 192.168.1.1
我曾尝试在print语句的末尾添加end
,但似乎无法正常工作(可能是因为我注意到正确使用了结束)