私は本当に混乱しています。このコードを書き、定義したいくつかの関数を取り込もうとしていますが、正しい情報をどこかに渡していないのです。誰かが何かヒントや指針を持っていますか?私の問題が何であるかを説明する方法がわかりませんが、エラーは次のとおりです。
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)