Home > OS >  Access variable from one function to another
Access variable from one function to another

Time:10-19

I have a following code snippet in python.

class Test():
    def a(self,dct,res_dct,lst):
        url_ls = []
        ....
        return url_ls
   
    def b(self):
        ....

I want to access the url_ls from a() to b(). How is it possible?

CodePudding user response:

def init() --> initialize self.urls After that, you can use it in both function (see doc POO)

CodePudding user response:

Why not making url_ls a class attribute? then you can acess it from every method. self.url_ls

class Test():
    def __init__(self):
        self.urls_ls = []

    def a(self,dct,res_dct,lst):
        url_ls = []
        ....
        self.urls_ls = url_ls
   
    def b(self):
        ....
  • Related