Reputation: 13
In my main script, I import some user specific data (another script):
main script:
.....
import a lot of things....
import acemedat
..... here goes the main code
the imported file ('acemedat.py'):
# some comment
azcor = 10 # value can be user dependent
... some other variables....
In the main script, I use acemedat.azcor and get the value 10 -- fine so far. In the main program, I want to change the value of azcor, write it to acemedat.py, and save it. The next time I start the main script, the new value is read. I know how to read acemedat.py and locate the correct line (I do it with a list of lines read from the file), but it works only with strings. Is there a way to avoid strings and change azcor directly?
Upvotes: 1
Views: 303
Reputation: 49803
The file is only strings (well, one big string); what is in that file is used to create the variable you are interested in (amongst other things).
So what you need to do is modify your file to contain the string representation of what you want your variable's value to be, as if you had opened the file in a text editor and typed in the representation of the new value yourself.
Upvotes: 1