'reload' a variable in python -
'reload' a variable in python -
so have next situation. have configuration class config.py holds number of scheme 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 have configuration file when exists overwrite couple of these variables. in order display these 'overwritable' configuration variables in ui i'm using genshi/cherrypy , have base of operations dictionary in settingsservice speficifies info (in setttingsservice.py):
from tvb.config import tvbsettings cfg configurable_keys = {'tvb_storage':{'label':'root used 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 cherrypy:', 'value':cfg.web_server_port, 'dtype':'primitive', 'type':'text'}, ... other entries ... }
now settingsservice.py has method update_configuration()
read configuration file , modifies default parameters frim cfg. works fine , changes seen troughout rest of system, configurable_keys dictionary still holds old values (i.e. in illustration above if cfg.tvb_storage modified configuration file, in dictionary old value still kept). i'm guessing it's same reason changes not done if do:
>>> class a: ... x = 1 >>> = {1: a.x} >>> a.x = 2 >>> {1: 1}
so question there way forcefulness python 'reload' variable take business relationship new changes.
edit (after sblom response):
that not alternative in case, cfg
a
illustration , configurable_keys
needs different entries number of different variabled cfg
.
regards, bogdan
if said a = {1: a}
, a.x = 2
, new value of a[1].x
2.
the reason it's not working written a.x plain old info type, not object reference. if utilize a
instead, is object reference, changes surfaced later.
python
Comments
Post a Comment