在Post方法中访问Instance变量的内容

时间:2014-01-07 05:18:35

标签: google-app-engine python-2.7

下面是我的代码片段

 def LoadCategory(self, filter_string):
        time.sleep(1)
        self.heading = ""

        self.Question_title = list()
        self.Question_tag = list()
        self.Question_body = list()
        self.Question_who_ask = list()
        self.Question_who_email = list()
        self.Question_key = list()
        self.Question_Date = list()
# list is then populated



   def post(self):          
                self.response.write(self.Question_body)

# want to print out self.Question_body in post method.

但是列表是空的。访问变量内容的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

快速解决方案,假设您在请求类中。尽管使用self为类分配变量并不像前面所说的那样好。

def LoadCategory(self, filter_string):
        time.sleep(1)
        self.heading = ""

        self.Question_title = list()
        self.Question_tag = list()
        self.Question_body = list()
        self.Question_who_ask = list()
        self.Question_who_email = list()
        self.Question_key = list()
        self.Question_Date = list()
# list is then populated



   def post(self):
                self.LoadCategory(filter_string)          
                self.response.write(self.Question_body)

如果将LoadCategory命名为load_category或loadcategory,也会更好。请尝试遵循PEP8,其中指出函数名称应为小写