문제

I have a kinda weird problem, here is my attempt at an explanation:

I'm currently making a program which opens a txt file and then reads a line for that file, using the following command linecache.getline(path,number), after the function is done I then use commmand linecache.clearcache.

If I then change something in the text file it keeps returning the pre-changed line.

Following is the code I'm using (I know it aint really pretty)

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()
도움이 되었습니까?

해결책

Nothing after the return statement will ever be executed. If you want to call clearcache, you need to call it before the return statement.

Also, as a side note, your del statements aren't really going to do anything either, even if they were placed before the return. del effectively just decrements the reference counter in the gc, which will happen when the interpreter exits the function scope anyway.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top