import gc
import os
gc.disable()
open('tmp.txt', 'w').close()
class A:
def __init__(self):
self.fo = open('tmp.txt')
a = A()
os.remove('tmp.txt')
When I execute the script, I got a PermissionError: [WinError 32]
.Then I try this:
import gc
import os
gc.disable()
open('tmp.txt', 'w').close()
class A:
def __init__(self):
self.fo = open('tmp.txt')
a = A()
# or a = None
del a
os.remove('tmp.txt')
Although it succeeded this time, but I don't know the reason. Could you tell me why?
My python version is 3.5.2.