我真的很困惑,我写了这段代码,我试图引入我定义的一些函数,但我没有在某处传递正确的信息。有没有人有任何提示或指示?我不确定如何描述我的问题,但错误是:
Traceback (most recent call last):
File "./test3.py", line 54, in <module>
bar()
File "./test3.py", line 26, in disconnectvpn
child.sendcontrol('c')
NameError: global name 'child' is not defined
我的固定程序代码如下所示:
def foo():
child = pexpect.spawn ('./script.sh -arg1')
child.expect ('(?i)user input:')
child.sendline ('response')
return child
def bar(child):
child.sendcontrol('c')
a = foo()
bar(a)