Subprocess with variables & Command from different class
============================================
Fixed
Manage to get this corrected heres the correct way of doing this for future viewers: http://pastebin.com/uM0z8Q2v
========================================开发者_JAVA百科====
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
You're not returning anything from filename()
. When you don't return anything, None
is returned instead, so the parameter command
to tcpdump
is None
, which gives you the error: you can't call split()
on the None
object.
Change the filename()
function in the Model
class to return a string.
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.
Manage to get this corrected heres the correct way of doing this for future viewers: http://pastebin.com/uM0z8Q2v
精彩评论