在Python中,我有一个for循环,它调用一个类,后者又调用另一个类,依此类推,类操作数据,执行sql插入等.最后一个类包含已创建的所有文件的列表.我想从课外访问这个列表,但我无法弄清楚如何!
(我知道还有一个循环问题 - 将在下面解释更多!)
一个基本的例子是:
#A class to create the list
class Create_list():
def list(self,j):
l=j+1
#pass this variable to another class, get_list
Get_list().input(l)
#class get_list receives the number from create_list and appends it to mylist
class Get_list():
def input(self,l):
mylist=[]
mylist.append(l)
#print mylist
# loop through a list of numbers and feed them into the create_list class
j=10
for k in range(j):
Create_list().list(k)
#I want to access the list here. I have tried all of the below …Run Code Online (Sandbox Code Playgroud) python ×1