如何将变量传递给sendline作为参数

时间:2016-02-09 06:45:10

标签: python

我正在尝试从文件中获取输入并逐行读取并将其传递给sendline,如下所示。但它说无效的语法。如何将变量发送到发送线?

cmds = open("argv[1]","r")
i = 0
while ( i < 2):
    cmd = cmds.readline()
    telconn.sendline(cmd);
    telconn.expect (['#',pexpect.EOF])
    show_mpls[i] = telconn.before
    i = i+1
cmds.close()

1 个答案:

答案 0 :(得分:0)

这将为你做到

import sys
cmds = open(sys.argv[1],"r")
i = 0
while ( i < 2):
    cmd = cmds.readline()
    telconn.sendline(cmd);
    telconn.expect (['#',pexpect.EOF])
    show_mpls[i] = telconn.before
    i = i+1
cmds.close()