class Logic:
def __init__(self):
self.__intrebari = []
self.__raspunsuri = []
self.lista1()
def lista1(self):
a = 0
f = open("/Users/andreivaran/eclipse-workspace/lab8/Source/Domain/date.txt", "r")
for line in f:
a += 1
if a % 2 == 1:
intrebare = line
self.__intrebari.append(intrebare)
else:
raspuns = line
self.__raspunsuri.append(raspuns)
f.close()
是否有一种方法可以递归地从文件中读取内容?
我已经尝试过类似的操作,但是它给出了错误,是否应该设置停止条件? 请帮助,谢谢
class Logic:
def __init__(self):
self.__intrebari = []
self.__raspunsuri = []
self.recursiv()
def recursiv(self):
f = open("/Users/andreivaran/eclipse-workspace/lab8/Source/Domain/date.txt", "r")
a = 1
for line in :
self.lista(a)
f.close()
def lista(self, a):
if a % 2 == 1:
self.__intrebari.append(self.line)
else:
self.__raspunsuri.append(self.line)
self.lista(a + 1)
RuntimeError:超过最大递归深度