Help with Borg design Pattern

Casey McGinty casey.mcginty at gmail.com
Mon Jun 30 04:52:24 EDT 2008


On Fri, Jun 27, 2008 at 5:25 PM, Maric Michaud <maric at aristote.info> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080629/86198f8a/attachment-0001.html>


More information about the Python-list mailing list