Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change a variable value in a python file from a python script

Tags:

python

I currently have a python file with a bunch of global variables with values. I want to change these values permanently from a separate python script. I've tried setattr and such but it doesnt seem to work. Is there a way to do this?

like image 215
lango Avatar asked Dec 23 '22 00:12

lango


1 Answers

The short answer is: don't. It won't be worth the trouble.

It sounds like you are trying to create a configuration file and then have your application update it. You should try using ConfigParser, a built-in module that can read and write configuration files for you with limited hassle: http://docs.python.org/library/configparser.html

like image 197
carl Avatar answered Dec 26 '22 10:12

carl