简体   繁体   English

在python的函数之间传递参数

[英]passing parameter between functions on python

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 我在google中搜索,但在这里找不到任何可以帮助我的东西

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' 我有这个错误: AttributeError: 'MainHandler' object has no attribute 'all_list'

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. self是传递给函数的实例,您现在正在做的只是将局部变量设置为函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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