带有变量和变量的子流程来自不同班级的命令
================================================
固定
管理纠正这个问题,这是为未来的观看者执行此操作的正确方法:http://pastebin.com/uM0z8Q2v
================================================
来源: http://pastebin.com/utL7Ebeq
我的想法是,如果我从控制器类“main”运行 它将允许我从类“模型”中获取“数据”,def“文件名”。 这似乎不起作用。正如您可以在下面看到我的意思
class Controller:
def __init__(self):
self.model = Model()
self.view = View()
def main(self):
data = self.model.filename()
self.view.tcpdump(data)
class View:
def tcpdump(self, command):
subprocess.call(command.split(), shell=False)
当我运行我的代码时,我收到此错误:
subprocess.call(command.split(), shell=False)
AttributeError: 'NoneType' object has no attribute 'split'
我的猜测意味着它没有获取命令(查看源代码以供参考)或者它没有获取带有变量的命令。但我知道当变量没有被拾取时会出现错误,所以我不认为是这样。
我的问题是,从目前为止我所掌握的情况来看,我如何从“类视图”中获取“命令”来运行我的子进程。
谢谢~
约翰·里塞尔瓦托
============================================
Fixed
Manage to get this corrected heres the correct way of doing this for future viewers: http://pastebin.com/uM0z8Q2v
============================================
source:
http://pastebin.com/utL7Ebeq
My thinking is that if i run from controller class "main"
it will allow me to take the "data" from Class "model", def "filename".
It doesn't seem to work. As you can see below what i mean
class Controller:
def __init__(self):
self.model = Model()
self.view = View()
def main(self):
data = self.model.filename()
self.view.tcpdump(data)
class View:
def tcpdump(self, command):
subprocess.call(command.split(), shell=False)
When i run my code i get this error:
subprocess.call(command.split(), shell=False)
AttributeError: 'NoneType' object has no attribute 'split'
My guess means that its not picking up command (look at source for reference) or that its not getting command with variables. But i know the error when variables are not being picked up so i don't think it is that.
My question is, from what i have thus far, how do i from "class view" grab "command" for my subprocesses to run.
Thanks~
John Riselvato
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不会从
filename()
返回任何内容。当不返回任何内容时,会返回None
,因此tcpdump
的参数command
为None
,这会出现错误:您无法在None
对象上调用split()
。更改
Model
类中的filename()
函数以返回字符串。You're not returning anything from
filename()
. When you don't return anything,None
is returned instead, so the parametercommand
totcpdump
isNone
, which gives you the error: you can't callsplit()
on theNone
object.Change the
filename()
function in theModel
class to return a string.在第 20 行之后,添加:
return self.raw
由于您没有从函数中返回任何内容,因此函数返回
None
,这就是您收到错误的原因。After line 20, add:
return self.raw
Since you don't return anything from the function, the function returns
None
and that is why you get the error.设法纠正此问题,这是为未来查看者执行此操作的正确方法:http://pastebin.com/uM0z8Q2v
Manage to get this corrected heres the correct way of doing this for future viewers: http://pastebin.com/uM0z8Q2v