I tried to import a list from another class in Python 3, but I always get an empty list. I researched the problem and found similar questions here on stackoverflow and elsewhere, however they didn't work. Because in my class i had an init method. And that interfered with their answers.
I'm posting a dummy code here to give you an idea of my code:-
main.py:-
number_of_cars = 3
factory = "XYZ"
class Home:
big_list = []
def __init__(self, _cars, _factory):
self.cars = _cars
self.factory = _factory
def add_to_list(self):
for x in range(0, 3):
self.big_list.append(x)
print(self.big_list)
def main():
home = Home(number_of_cars, factory)
home.add_to_list()
if __name__ == '__main__':
main()
extra.py:-
from main import Home
class Extra:
def print_func(self):
number_of_cars = 3
factory = "XYZ"
x = Home(number_of_cars, factory).big_list
print(x)
if __name__ == '__main__':
extra = Extra()
extra.print_func()
What I tried:- -I tried using the getattr(home, 'all_addresses'), it didn't work -I tried to write Home().all_addresses, but that resulted in an error of I have to enter number_of_cars and factory, again, which will result in an error while I run my actual code
I know I didn't post my actual code, I'm sorry for that, but that's for security reasons.
Thanks in advance...