Howto: creating empty modules?

Janko Hauser jhauser at ifm.uni-kiel.de
Wed Jan 9 07:11:02 EST 2002


"Alex Martelli" <aleax at aleax.it> writes:

> "Ville Vainio" <vvainio at karhu.tp.spt.fi> wrote in message
> news:yoxelkzrgnh.fsf at karhu.tp.spt.fi...
> > How should I go about creating an empty module?
> >
> > I mean
> >
> > config = make_empty_module()
> > config.someattr = "hi"
> 
> Any module has a name, even an empty one.  As you don't
> seem to want to pass a name to the make_empty_module function,
> you presumably want that function to generate some artificial
> unique name?  You'll have to clarify that.
> 

It seems to me the name should be config. And with such a name it
looks like the OP wants to share information between modules, which is
not possible with this approach, if I'm not mistaken. 

If he just wants to have a place to store configuration in the calling module
an empty class would be enough.

class EmptyClass:
    pass

config=EmptyClass()
config.someattr = 'hi'

For variations on this theme (singleton) look for posts from Alex
Martelli :-).

__Janko

-- 
  Institut fuer Meereskunde             phone: 49-431-597 3989
  Dept. Theoretical Oceanography        fax  : 49-431-565876
  Duesternbrooker Weg 20                email: jhauser at ifm.uni-kiel.de
  24105 Kiel, Germany



More information about the Python-list mailing list