I have a variables.py file with a key TOKEN= 123456. I need to update that value dynamically when ever it required.
The file Constants.py reads:
#!/usr/bin/env python
# encoding: utf-8
"""
variables.py
"""
TOKEN= 50
And refresh_tok.py
#!/usr/bin/env python
# encoding: utf-8
"""
refresh_tok.py
"""
import variables
def refresh_token():
print(variables.TOKEN) // previous value 50
change_constant(variables.TOKEN, 100)
print(variables.TOKEN) // value I am expecting is 100 but it says 50
def change_constant(match_string, replace_string):
read_file = open("variables.py", "rt")
read_data = read_file.read()
read_data = read_data.replace(match_string, replace_string)
read_file.close()
write_file = open("variables.py", "wt")
write_file.write(read_data)
write_file.close()
Value that I am expecting in 2nd print statement in refresh_tok.py is 100 but it is still on previous value and print 50 rather then 100.
inspectmodule: docs.python.org/3/library/inspect.html maybe you'll find it helpful :)