Reputation: 8236
So I have the following situation. I have a configuration class config.py that holds a number of system setting variables like:
class TVBSettings():
TVB_CONFIG_FILE = os.path.expanduser(os.path.join("~", 'tvb.configuration'))
TVB_STORAGE = os.path.expanduser(os.path.join("~", "TVB" + os.sep))
.... etc ...
Now besides this I have a configuration file that when it exists will overwrite a couple of these variables. In order to display these 'overwritable' configuration variables in the UI I'm using genshi/cherrypy and I have a base dictionary in a SettingsService that speficifies some info like (in setttingsservice.py):
from tvb.config import TVBSettings as cfg
CONFIGURABLE_KEYS = {'TVB_STORAGE':{'label':'Root used for all you projects:',
'value':cfg.TVB_STORAGE,
'type':'text'},
'SERVER_IP':{'label':'Server name:',
'value':cfg.SERVER_IP,
'type':'text'},
'WEB_SERVER_PORT':{'label':'The port used by cherrypy:',
'value':cfg.WEB_SERVER_PORT,
'dtype':'primitive',
'type':'text'},
... other entries ... }
Now this settingsservice.py also has a method update_configuration()
that read from the configuration file and modifies the default parameters frim cfg. This works fine and the changes are seen troughout the rest of the system, however the CONFIGURABLE_KEYS dictionary still holds the old values (i.e. in the example above even if cfg.TVB_STORAGE is modified from the configuration file, in the dictionary the old value is still kept). Now I'm guessing it's for the same reason that the changes are not done if I do:
>>> class A:
... x = 1
>>> a = {1: A.x}
>>> A.x = 2
>>> a
{1: 1}
So my question would be is there any way to force python to 'reload' that variable to take into account the new changes.
EDIT (after sblom response):
That is not really an option in my case, cfg
would be the A
from that example and CONFIGURABLE_KEYS
needs different entries for a number of different variabled from cfg
.
Regards, Bogdan
Upvotes: 0
Views: 3075
Reputation: 27343
If you said a = {1: A}
, then A.x = 2
, the new value of a[1].x
would be 2.
The reason it's not working as written is that A.x is a plain old data type, not an object reference. If you use something like A
instead, which is an object reference, changes to it will be surfaced later.
Upvotes: 1