简体   繁体   中英

Calling Methods Inside Another Method In a Different Class

I am having a difficult time trying to figure out the correct way on how to call methods inside a method that happens to be in a different class.

Here's my code:

runner,py

import reader as bb



class monitorRunner():

  def __init__(self):
    self.url = sys.argv[1]
    self.store = None
  
  def executeLink(self):
    self.determineStore()
    bb.BestBuyMonitor.executeBestBuyMonitor(self,self.url,self.store)

  def determineStore(self):

    -code-
  

if __name__== "__main__":
    taskMaster =  monitorRunner()
    taskMaster.executeLink()

reader.py

class BestBuyMonitor():

  def __init__(self):
    -variables-


  def executeBestBuyMonitor(self,store,url):
    self.getAPiData()
  
  def getAPiData(self):
    -code-

Trace:

self.getAPiData()
AttributeError: 'monitorRunner' object has no attribute 'getAPiData'

Not quite sure how to fix this, any help would be appriciated.

You missed instantiating the class. Use () after class's name:

import reader as bb



class monitorRunner():

  def __init__(self):
    self.url = sys.argv[1]
    self.store = None
  
  def executeLink(self):
    self.determineStore()
    bb.BestBuyMonitor().executeBestBuyMonitor(self.store,self.url)

  def determineStore(self):

    -code-
  

if __name__== "__main__":
    taskMaster =  monitorRunner()
    taskMaster.executeLink()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM