ဖိုင်တွေကိုဖျက်ဖို့အတွက် Python ရဲ့ os module ကိုသုံးရပါတယ်။ os.path.exists() နဲ့ ဖိုင်ရှိမရှိ အရင်စစ်ဆေးသင့်ပါတယ်။
python
import os
file_to_delete = "dummy_file.txt"
with open(file_to_delete, "w") as f:
f.write("Temp file.")
print(f"'{file_to_delete}' created.")
if os.path.exists(file_to_delete):
os.remove(file_to_delete)
print(f"'{file_to_delete}' has been deleted.")You should see
'dummy_file.txt' created. 'dummy_file.txt' has been deleted.