Properties for modules?
Ed Leafe
ed at leafe.com
Mon Jun 11 17:35:00 EDT 2007
I have a simple module that reads in values from disk when imported,
and stores them in attributes, allowing for code like:
>>> import moduleFoo
>>> print moduleFoo.someSetting
'the value'
What I'd like to do is have a more property-like behavior, so that
if they try to set the value of moduleFoo.someSetting, it also
persists it to disk. But properties are really only useful in
instances of classes; if I define 'someSetting' as a property at the
module level, I get:
>>> import moduleFoo
>>> print moduleFoo.someSetting
<property object at 0x78a990>
Does anyone know any good tricks for getting property-like behavior
here?
-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com
More information about the Python-list
mailing list