0

I have a dictionary in python code containing few keys and their values, I want to know if it is possible to update a value such that if I open the code in editor after updating the value, I see the updated value in the dictionary?

Progman
  • 16,827
  • 6
  • 33
  • 48
  • 2
    You should probably store that dictionary in another file, stored as a json object, so you can load it from that file every time the program runs, and update it when you need to (user input etc). Take a look at the `json` module, and especially `loads` and `dumps`. – Elro444 Apr 21 '19 at 10:54
  • Thanks, Is there any alternative? – Paras Jain Apr 21 '19 at 11:19
  • 1
    Don't think so.. I mean, you could theoretically have your script edit itself, to put the changes, but that is basically the same thing as saving to an other file, just more complicated for no good reason.. – Elro444 Apr 21 '19 at 11:36
  • As @Elro444 says having a script editing itself it's complicated. In my opinion is not a good idea, but if you really want to do this way, have a look here: https://stackoverflow.com/questions/39643428/how-can-i-make-a-python-script-change-itself – Valentino Apr 21 '19 at 12:59

0 Answers0