Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64508

Re: SIngleton from __defaults__

References <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com>
Date 2014-01-23 03:18 +1100
Subject Re: SIngleton from __defaults__
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.5843.1390407541.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las <roegltd@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 singleton_provider.__defaults__[0][0]
>

Why not simply:

def get_singleton(x = SomeClass()):
    return x

Or even:

singleton = SomeClass()

? Neither of the above provides anything above the last one, except
for late creation.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

SIngleton from __defaults__ Asaf Las <roegltd@gmail.com> - 2014-01-22 08:07 -0800
  Re: SIngleton from __defaults__ Chris Angelico <rosuav@gmail.com> - 2014-01-23 03:18 +1100
    Re: SIngleton from __defaults__ Asaf Las <roegltd@gmail.com> - 2014-01-22 08:37 -0800
      Re: SIngleton from __defaults__ 88888 Dihedral <dihedral88888@gmail.com> - 2014-01-22 09:23 -0800
      Re: SIngleton from __defaults__ Ned Batchelder <ned@nedbatchelder.com> - 2014-01-22 14:18 -0500
        Re: SIngleton from __defaults__ Asaf Las <roegltd@gmail.com> - 2014-01-22 11:52 -0800
      Re: SIngleton from __defaults__ Johannes Schneider <johannes.schneider@galileo-press.de> - 2014-01-23 14:36 +0100
      Re: SIngleton from __defaults__ Dave Angel <davea@davea.name> - 2014-01-23 11:56 -0500
      Re: SIngleton from __defaults__ Terry Reedy <tjreedy@udel.edu> - 2014-01-23 19:10 -0500
      Re: SIngleton from __defaults__ Johannes Schneider <johannes.schneider@galileo-press.de> - 2014-01-24 09:20 +0100
    Re: SIngleton from __defaults__ Asaf Las <roegltd@gmail.com> - 2014-01-22 13:10 -0800
    Re: SIngleton from __defaults__ Asaf Las <roegltd@gmail.com> - 2014-01-22 14:34 -0800

csiph-web