Singleton implementation problems

Ben Finney bignose+hates-spam at benfinney.id.au
Fri Jul 4 09:12:49 CEST 2008


Peter Otten <__peter__ at web.de> writes:

> The problem is the structure of your program. The myset module is
> imported twice by Python, once as "myset" and once as "__main__".

Yes, this is the problem. Each module imports the other.

> Therefore you get two distinct MySet classes, and consequently two
> distinct MySet.__instance class attributes.

Are you sure? This goes against my understanding: that 'import foo'
will not re-import a module that's already been imported, but will
instead simply return the existing module.

So, I think if one evaluated 'myset is __main__', you'd find they are
exactly the same module under different names; and therefore that
there is only *one* instance of 'MySet', again under two names.

-- 
 \                “Science doesn't work by vote and it doesn't work by |
  `\        authority.” —Richard Dawkins, _Big Mistake_ (The Guardian, |
_o__)                                                      2006-12-27) |
Ben Finney



More information about the Python-list mailing list