Python: Calling module's functions from within a class -


i have following code:

from suchandsuch import bot  class lalala():     def __init__(self):         self.donenow = 0         print "lalala() initialized."         return      def start(self):         pages = bot.cats_recursive('something')         page in pages:             self.process_page(page) 

when try run y = lalala() , y.start(), though, error:

attributeerror: lalala instance has no attribute 'cats_recursive' 

this makes me suspect python trying call cats_recursive() not suchandsuch's bot sub-module (as defined @ beginning of file), rather lalala(), of course doesn't have cats_recursive() function. there way force class instance use imported module, rather inside itself?

posters correct there nothing wrong code have posted.

it's code didn't post problem. hinted @ in naming of cats_recursive. haven't shown perhaps lalala defined in or imported bot.py.

one way replicate error is:

# in suchandsuch/bot.py  class lalala():     def __init__(self):         self.donenow = 0         print "lalala() initialized."         #  don't need `return` here  def start(self):     pages = bot.cats_recursive('something')     page in pages:         self.process_page(page)  bot = lalala() 

that's one. have __init__.py in such , such like:

bot = lalala() 

like said, error in code structure.

print id of bot inside lalala or captrue error pydb , suspect see bot instance of lalala other y (again check id's)


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -