我有一个奇怪的问题,这是我的解释尝试:
我目前正在制作一个程序,它打开一个 txt 文件,然后使用以下命令 linecache.getline(path,number) 为该文件读取一行,在函数完成后,我使用命令 linecache.clearcache。
如果我随后更改文本文件中的某些内容,它会不断返回预先更改的行。
以下是我正在使用的代码(我知道它不是很漂亮)
def SR(Path,LineNumber):
returns = lc.getline(Path,LineNumber)
x = np.array([])
y = np.array([])
words = returns.split()
for word in words:
x = np.append([x],[word])
for i in range(len(x)):
t = float(x[i])
y = np.append([y],[t])
return y
del x
del y
del t
del words
lc.clearcache()