I want to know how to delete/clear all text inside another python file, I looked through stack overflow and could not find a answer, all help appreciated. Thanks!
Asked
Active
Viewed 139 times
3 Answers
4
Just as you would a text file:
with open("file_to_clear.py", "w") as file:
file.write("")
I think that's what you're looking for. You were probably being misled because all the examples are on text files, but it works with Python files too!

Jack Parkinson
- 681
- 11
- 35
0
Things to look into(google terms) to get your answer:
- How to open/read a .py file using a python script
- How to overwrite/clear content of a file using python
- Python overwrite file
- Python read file. Python write file. Python delete file.
Once you have tried all of the following, and are still struggling with the task. Please review https://stackoverflow.com/help/how-to-ask, and feel to free to rework/edit your question.

Akib Rhast
- 651
- 4
- 15