Re: SIngleton from __defaults__

2014-01-24 Thread Johannes Schneider
thnx guys. On 24.01.2014 01:10, Terry Reedy wrote: Johannes Schneider johannes.schnei...@galileo-press.de Wrote in message: On 22.01.2014 20:18, Ned Batchelder wrote: On 1/22/14 11:37 AM, Asaf Las wrote: Chris is right here, too: modules are themselves singletons, no matter how many times

Re: SIngleton from __defaults__

2014-01-23 Thread Johannes Schneider
On 22.01.2014 20:18, Ned Batchelder wrote: On 1/22/14 11:37 AM, Asaf Las wrote: Chris is right here, too: modules are themselves singletons, no matter how many times you import them, they are only executed once, and the same module object is provided for each import. I'm not sure, if this is

Re: SIngleton from __defaults__

2014-01-23 Thread Dave Angel
Johannes Schneider johannes.schnei...@galileo-press.de Wrote in message: On 22.01.2014 20:18, Ned Batchelder wrote: On 1/22/14 11:37 AM, Asaf Las wrote: Chris is right here, too: modules are themselves singletons, no matter how many times you import them, they are only executed once, and the

Re: SIngleton from __defaults__

2014-01-23 Thread Terry Reedy
Johannes Schneider johannes.schnei...@galileo-press.de Wrote in message: On 22.01.2014 20:18, Ned Batchelder wrote: On 1/22/14 11:37 AM, Asaf Las wrote: Chris is right here, too: modules are themselves singletons, no matter how many times you import them, they are only executed once, and

SIngleton from __defaults__

2014-01-22 Thread Asaf Las
Hi Inspired by Modifying the default argument of function https://groups.google.com/forum/#!topic/comp.lang.python/1xtFE6uScaI is it possible to create singleton using construct below : def singleton_provider(x = [None]): if singleton_provider.__defaults__[0][0] == None:

Re: SIngleton from __defaults__

2014-01-22 Thread Chris Angelico
On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las roeg...@gmail.com wrote: is it possible to create singleton using construct below : def singleton_provider(x = [None]): if singleton_provider.__defaults__[0][0] == None: singleton_provider.__defaults__[0][0] = SomeClass() return

Re: SIngleton from __defaults__

2014-01-22 Thread Asaf Las
On Wednesday, January 22, 2014 6:18:57 PM UTC+2, Chris Angelico wrote: On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las r@gmail.com wrote: Why not simply: def get_singleton(x = SomeClass()): return x Or even: singleton = SomeClass() ? Neither of the above provides anything above the last

Re: SIngleton from __defaults__

2014-01-22 Thread 88888 Dihedral
On Thursday, January 23, 2014 12:37:36 AM UTC+8, Asaf Las wrote: On Wednesday, January 22, 2014 6:18:57 PM UTC+2, Chris Angelico wrote: On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las r@gmail.com wrote: Why not simply: def get_singleton(x = SomeClass()): return x Or

Re: SIngleton from __defaults__

2014-01-22 Thread Ned Batchelder
On 1/22/14 11:37 AM, Asaf Las wrote: On Wednesday, January 22, 2014 6:18:57 PM UTC+2, Chris Angelico wrote: On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las r@gmail.com wrote: Why not simply: def get_singleton(x = SomeClass()): return x Or even: singleton = SomeClass() ? Neither of the above

Re: SIngleton from __defaults__

2014-01-22 Thread Asaf Las
On Wednesday, January 22, 2014 9:18:19 PM UTC+2, Ned Batchelder wrote: Chris is right here, too: modules are themselves singletons, no matter how many times you import them, they are only executed once, and the same module object is provided for each import. Ned Batchelder,

Re: SIngleton from __defaults__

2014-01-22 Thread Asaf Las
On Wednesday, January 22, 2014 6:18:57 PM UTC+2, Chris Angelico wrote: On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las r...@gmail.com wrote: is it possible to create singleton using construct below : def singleton_provider(x = [None]): if singleton_provider.__defaults__[0][0] == None:

Re: SIngleton from __defaults__

2014-01-22 Thread Asaf Las
On Wednesday, January 22, 2014 6:18:57 PM UTC+2, Chris Angelico wrote: On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las r...@gmail.com wrote: ChrisA and this one is about multiclass container function with multithreading support: import threading def provider(cls, x = [threading.Lock(), {}]):