Global package variable, is it possible?

Chris Allen ca.allen at gmail.com
Mon Aug 6 18:18:11 EDT 2007


On Aug 6, 2:27 am, Ben Finney <bignose+hates-s... at benfinney.id.au>
wrote:
> Bruno Desthuilliers <bruno.42.desthuilli... at wtf.websiteburo.oops.com> writes:
> > I've read all the thread, and it seems that your problem is mostly
> > to share a single dynamic state (the config) between several
> > modules. So I do wonder: have you considered the use of the
> > Singleton pattern (or one of it's variants...) ?
>
> Python modules are effectively singletons. So the idiomatic way to do
> this is to create a module for configuration (perhaps named 'config'),
> import that into every other module that needs it, and use its
> attributes.
>
> --
>  \       "[On the Internet,] power and control will shift to those who |
>   `\       are actually contributing something useful rather than just |
> _o__)                                 having lunch."  -- Douglas Adams |
> Ben Finney

Yes, that's what I ended up doing.  Which is creating a configure
module and then importing it into my modules that use it.  I did
something very similar to the code I posted above.





More information about the Python-list mailing list