Skip to content Skip to sidebar Skip to footer

Closing A File After Using Np.load (using Spyder)

I am loading a file: a= np.load('myfile.npz') and then doing things with a After a while I regenerate myfile.npz (on a remote machine). When I attempt to copy the file across (usi

Solution 1:

Try using the with context manager:

with np.load('myfile.npz') as a:
    do_stuff(a)

do_morestuff() # a is closed now

Context managers automatically take care of closing the resource once you are done with it.

Solution 2:

I have found that using del also works:

dela

Post a Comment for "Closing A File After Using Np.load (using Spyder)"