1

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'

1
  • You didn't store all_list in .get() on self.. And this is about managing instance state, not about passing parameters between functions (or methods). Commented Apr 17, 2013 at 9:03

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

8 Comments

@Tasos You must have called post before you called get. You probably want to set up self.all_list = [] in the __init__ method
Nop. I call post after get. That's for sure. Also, I don't have any init method. I will create one only for this?
@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 []
I use jinja framework. Get is the function to load the page and post when someone submit a form. So, first 'get' called to load the page and then 'post' when form submited.
Yes. I put self.all_list to both defs. Sorry if bother you, but I cannot really find a way
|