【问题标题】:How can put variable in tn.write?如何将变量放入 tn.write?
【发布时间】:2021-04-28 07:03:06
【问题描述】:

我想在我制作的脚本中放入一个变量

我们说

host = 192.168.1.1

我在脚本中的评论是:

tn.write("cpconf tohost=192.168.200.22:XXX \n")

我的要求: 想要改为 XXX 它的变量将是主机

怎么办? 使用Python2.7

【问题讨论】:

  • tn.write("cpconf tohost=192.168.200.22:{0} \n".format(host))
  • 作为初学者,您不应该花时间学习 Python 2。我们这些仍在编写它的人这样做是因为我们必须支持遗留代码。请考虑安装 Python 3.9 并学习用它来编写代码。

标签: python python-2.7 telnetlib


【解决方案1】:
tn.write("cpconf tohost=192.168.200.22:{0} \n".format(host))

工作!谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    • 2017-02-04
    • 2012-03-22
    • 2018-02-10
    • 2021-04-09
    • 2013-01-07
    相关资源
    最近更新 更多