我有一个奇怪的问题,我想解释一下:
我目前正在制作一个程序,它打开一个txt文件,然后读取该文件的一行,使用以下命令linecache.getline(path,number),函数完成后,我使用commmandlinecache.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()
不会执行
return
语句后的任何内容。如果要调用clearcache
,则需要在return
语句之前调用它。在另外,作为补充说明,您的
del
语句也不会真正起任何作用,即使它们被放在return
之前。del
有效地减少gc中的引用计数器,这将在解释器退出函数作用域时发生。在相关问题 更多 >
编程相关推荐