I try to use a parameter of another function. I prefer to not use global variable. I try the following one, but I have an error. I search in google and here but I haven't found something to help me
class MainHandler(BaseHandler):
def get(self):
******
all_list = *a list*
******
def post(self):
for i in self.all_list:
if i[0] == something:
****
And I have this error: AttributeError: 'MainHandler' object has no attribute 'all_list'
asked Apr 17, 2013 at 9:02
user2023413
1 Answer 1
You need to set
self.all_list = *a list*
self is the instance that gets passed to the function, what you are doing at the moment is just setting a local variable to the function.
answered Apr 17, 2013 at 9:03
jamylak
135k30 gold badges238 silver badges240 bronze badges
Sign up to request clarification or add additional context in comments.
8 Comments
jamylak
@Tasos You must have called
post before you called get. You probably want to set up self.all_list = [] in the __init__ methodjamylak
@Tasos Oviously you don't... or this error wouldn't arise, put some debugging statements into your code and it's probably best to create an
__init__ method to set up and empty [] |
lang-py
all_listin.get()onself.. And this is about managing instance state, not about passing parameters between functions (or methods).