英文:
How can I clear the memory of an import file in python with a while loop
问题
I have a while loop, and inside of it, various .py files are imported.
As it is now, when it loops a second time, those .py files are not imported again.
The .py file creates a DataFrame and makes a CSV, but when it loops, it doesn't import the .py file again, so it uses an old CSV.
I've tried deleting the CSV, but the issue is because it doesn't import the file.py in each loop.
Is there a way to make it import the files every time it goes through a loop?
I tried using gc.collect()
, but it didn't work.
while True:
if a == 1:
import d1makecsv
df = pd.read_csv(d1)
os.remove('d1.csv')
if a == 2:
import d2makecsv
df = pd.read_csv(d2)
os.remove('d2.csv')
else:
print("my mom is fat")
df_make_calcs = df
英文:
I have a while loop, and inside of if various import .py
As it is now, when it loops a second time, those import .py files, don't get imported again.
the .py file, creates a df, and makes a csv ... but when it loops, it doesnt import again that .py so it takes an old csv ...
I've tried making delete the csv, but the error is because it doesn't import the file.py in each loop.
Is there some way to make it import the files, each time it makes a loop?
If tried with gc.collect()
and it doesn't work.
while (true):
if a == 1:
import d1makecsv
df=pd.read_csv(d1)
os.remove('d1.csv')
if a == 2:
import d2makecsv
df=pd.read_csv(d2)
os.remove('d2.csv')
else:
print("my mom is fat")
df_make_calcs=df
答案1
得分: 0
尝试这个
import importlib
importlib.reload(YOUR_MODULE)
英文:
Try this
import importlib
importlib.reload(YOUR_MODULE)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论