我在类中调用变量时遇到问题。我把所有的事情都安排好了,但我还是犯了错误。我想我很难弄清楚这一点,因为我是3.0脚本新手。在
这是我的剧本:
http://pastebin.com/9Lrw399E
错误如下:
command = 'tcpdump -c5 -tttt -w {0} host {1}'.format(raw, input_host)
NameError: global name 'raw' is not defined
如果我做的话自我。原始或者self.input_主机在
它得到这个:
^{pr2}$
Tags:
试试看
除非将raw和input_host作为函数参数传入,否则需要使用自变量查找类实例的变量。在
编辑:您还需要确保任何函数定义自我。原始以及self.input_主机在运行这行代码之前调用。从代码中,如果您调用},这样}存在于类的实例中。在
MainLoop.cmd()
,则必须在cmd()
之前调用MainLoop.host()
和{self.raw
和{在这种情况下,您可能应该为类创建一个至少创建实例变量的构造函数
^{pr2}$然后检查自我。原始以及self.input_主机在创建命令之前。在
应该是:
^{pr2}$注意
self
。在相关问题 更多 >
编程相关推荐