fin = open('/abc/xyz/test.txt', 'a+')
def lst():
return fin.read().splitlines()
print lst()
def foo(in):
print lst()
fin.write(str(len(lst()) + in)
fin.flush()
In above code when print lst()
is called outside function it gives correct result, but when trying to call same function in function foo()
it produces empty list which makes len(lst())
value 0. I also tried by commenting last two line but still it gives back empty list. What is wrong in above code?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…