I'm building a QGIS 3.0 plugin and trying to organise my code into several files. I have three files - a main python script and two other scripts stored in a subfolder. Excerpts provided below:
from .mod import pmp as pmp from .mod import helpers as h class MyPlugin: def __init__(self, iface): self.iface = iface [...] h.msgInfo(self,"Plugin initialised!") pmp.test(self)
import qgis.core as qgisCore from qgis.core import Qgis, QgsApplication, QgsMessageLog from qgis.gui import QgsMessageBar def msgInfo(self, message, **kwargs): title = kwargs.get('t','') dur = kwargs.get('d',10) self.iface.messageBar().pushMessage(title, message, level=qgisCore.Qgis.Info, duration=dur)
from . import helpers as h def test(self): h.msgInfo(self,"PMP module successfully imported!")
Importing "helpers" is working perfectly for myplugin.py, as the "Plugin initialised!" message is showing as expected. Similarly, importing "pmp" seems to be working for myplugin.py. But when myplugin.py gets to this line:
I get this error:
TypeError: test() takes 0 positional arguments but 1 was given
I've tried "self.pmp.test()" instead, but then of course I get "AttributeError: 'myplugin' object has no attribute 'pmp'".
If I use just "pmp.test()", then pmp.py gives me "NameError: name 'self' is not defined".