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) fi
File object can only read once which means if you'v called fin.read() before the later fin.read() will return nothing.
fin.read()
fix this by call fin.seek(0) after call fin.read(), or read file to some buffer.
fin.seek(0)