On Fri, Jun 27, 2008 at 5:25 PM, Maric Michaud <[EMAIL PROTECTED]> wrote:
> Yes it is, but it's rather unneeded in Python, we prefer simply create a > module level dictionnary, these tricks are used in language like C++ or > Java. > > In python : > > mymodule.py : > > ModuleOptions = {} > > othermodule.py : > > import mymodule > > mymodule.ModuleOptions['Verbose'] = True > > or if you think encapsulation is important : > > mymodule.py : > > _ModuleOptions = {} > > def get_option(opt) : > return _ModuleOptions[opt] > .... > > And you're done. > > Using a module level instance seems the right way to go. I'm trying something like this. mymodule.py: class MyDict( dict): ... ... MyDict = MyDict() othermodule.py: import mymodule print mymodule.MyDict I'm running into a slight problem however that my run-time defined logging level is not correctly set until after the module has initialized, preventing any log messages from showing up. Is there a pythonic way to get around this? I'm thinking of adding a module init routine, but I don't feel like this is clean solution. - Casey
-- http://mail.python.org/mailman/listinfo/python-list