Sorry if the question is not directly related to WxPython, even if I’m using it for this project. I’m struggling with this problem for 2 days and I can’t find any help
I have a parent Class that has a setter that returns queryFiltre value and a getter that is supposed to pass the queryFiltre value to my child Class. queryFiltre Should return an SQL query like "SELECT * FROM Report WHERE GA_RPM > 0 and CAMPAIGN LIKE ‘%TT%’… ".
The print() in the setter returns a SQL query, but the print() of the getter, when called in the child Class, returns something like " <main.SimpleGrid object at 0x042AF2B0>".
What’s wrong with my code? Please bear with me as I’m still learning and oop is still an abstract concept in my head.
I’ve added comments in the code so you can see what happens where:
class SimpleGrid(gridlib.Grid): ##, mixins.GridAutoEditMixin):
def __init__(self, parent, log):
gridlib.Grid.__init__(self, parent, -1)
########### DATABASE CONNECT
self.path =os.path.dirname(os.path.realpath(__file__))
self.dbfile = os.path.join(self.path , "report.db")
self.db_conn = sqlite3.connect(self.dbfile)
self.theCursor = self.db_conn.cursor()
########### SETTING FILE CONNECT
self.configFile = os.path.join(self.path , "config.ini")
self.config = configparser.ConfigParser()
self.config.read(self.configFile)
########### Calling th Getter and Setter
self.queryFiltre = self.setQueryFiltre(self)
self.getQueryFiltre()
########### Setter
def setQueryFiltre(self,queryFiltre):
if self.config.get('Network', 'taboola') == "true" and self.config.get('Network', 'ob') == "true":
network = ""
elif self.config.get('Network', 'taboola') == "true" and self.config.get('Network', 'ob') == "false":
network = " and CAMPAIGN LIKE '%TB%'"
elif self.config.get('Network', 'outbrain') == "true" and self.config.get('Network', 'tb') == "false":
network = " and CAMPAIGN LIKE '%OB%'"
else:
network = ""
queryFiltre = "SELECT * FROM Report WHERE GA_RPM > 0 " + network + " and STATUS = '1' ORDER BY CLICKS DESC"
########### The print below returns the right value of queryFiltre
print(queryFiltre)
return queryFiltre
########### Getter
def getQueryFiltre(queryFiltre):
queryFiltre = queryFiltre
return queryFiltre
class TestFrame(wx.Frame):
def __init__(self, parent, log):
wx.Frame.__init__(self, parent, 0, "Native Ads Reports V1.0", size=(1400,800))
self.grid = SimpleGrid(self, log)
########### Calling the Getter of the parent Class
self.queryFiltre = self.grid.getQueryFiltre()
########### DATABASE CONNECT
self.path =os.path.dirname(os.path.realpath(__file__))
self.dbfile = os.path.join(self.path , "report.db")
self.db_conn = sqlite3.connect(self.dbfile)
self.theCursor = self.db_conn.cursor()
########### The print below returns a bad value, something like : <__main__.SimpleGrid object at 0x042AF2B0>
print(self.queryFiltre)
You’ll notice also that I’ve added the script to define the path and to connect to the db in both classes, is there a way to do it only once in the first Class?
Thank you,