[Tutor] Tips

Alex Kleider akleider at sonic.net
Thu Jun 19 20:10:26 CEST 2014

On 2014-06-18 18:37, Steven D'Aprano wrote:
> Python tries very hard to ensure that every module is loaded only once.
> (There are circumstances where you can fool it, but they're rare.) 
> Since
> the module holds state (variables) and behaviour (functions), modules
> perform the same sort of role as classes, so a module which is loaded
> once is very similar to a singleton instance. In other words, if you
> want a class to implement singleton behaviour, you have to work at it.
> But if you shift the functionality from the class into a module, Python
> gives you singleton behaviour for free.
> But if you're not sure why anyone would want a singleton instance, I
> agree with you: most (but not all) uses of singletons are unnecessary.

The idea of a singleton class is new to me as is this comparison of 
class vs module.
Can anyone suggest a place to turn for more discussion of the topic?
thks, alexK

More information about the Tutor mailing list