[Tutor] Tips
Albert-Jan Roskam
fomcl at yahoo.com
Thu Jun 19 21:33:33 CEST 2014
----- Original Message -----
> From: Alex Kleider <akleider at sonic.net>
> To: tutor at python.org
> Cc:
> Sent: Thursday, June 19, 2014 8:10 PM
> Subject: Re: [Tutor] Tips
>
> 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
Maybe this (it's about Singleton and Borg): http://stackoverflow.com/questions/1318406/why-is-the-borg-pattern-better-than-the-singleton-pattern-in-python
More information about the Tutor
mailing list