+ 1
How to modify my current code every time the code run
Is there is a way to open the file that is running the code and change in it ? I dont want variables update i want the letters to actually change
2 Answers
+ 1
Yes, there is a way to do that..
idk if there is better way for that..
you can open the file that you currently running using open(__file__).
Here is an example: https://code.sololearn.com/cNJuwOy29CFB
The code I just share to you will modify the second line of the code from `b = 2` to `b = 100` and then it will add 2 new lines of code at the end of the file.
So basically, it is the same as opening file using open(), but you use __file__ as the argument so it will open itself.
I hope this answer your question.
0
Thank you for answering
I can deal with files and understand your code.
But i was wondering if there was another way so i can alter the code while using some limited IDEs like sololearn