This probably already looks like a duplicate; here's the scenario:
default_config.py:
unit_id = -1 # a serial number; int. -1 is a test unit, for example
def um():
return unit_id % 60 # stagger uploads
upload_hour = 2 #am
upload_minute = property( um ) # <- something that works needed here...
config.py
from default_config import *
# Override defaults here, if necessary
unit_id = 12 # ACTUAL serial number...
some_file.py
import config as cfg
do_something(cfg.upload_hour, cfg.upload_minute)
print cfg.upload_minute * 5 # should be an int...?
So, the goals are:
- A specific config file can override the defaults, which works fine
- Some values which are calculated can be accessed - after the overrides are applied - but in a "transparent" way (ie. without the prop() brackets)
This seemed to be simple for python properties, but after various combinations, doesn't work. I guess its something to do with the function being defined on a module, not an object, and unbound first variables, etc...
Either I get a "property object" back, and can't then use operators on it, etc, or I can't get the value the property should calculate and return, or after many iterations I can't remember, some other error...