Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'none:': 0.07; 'cc:addr :python-list': 0.11; 'def': 0.12; 'jan': 0.12; '23,': 0.16; 'creation.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'singleton': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'subject:from': 0.34; 'except': 0.35; 'skip:s 30': 0.35; 'late': 0.35; 'one,': 0.35; 'received:google.com': 0.35; 'possible': 0.36; 'las': 0.37; 'anything': 0.39; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=6yy94tchLMATn8BFEQ2sNDe0arRY6argI8Or2zxnZLs=; b=gCovKu03UuS9DF1eSCwd0JY7789/NUDyHZXINqS5aUlHj3QV3YMNCCf8xnnqIRKSCh Z2snha2unSmsz90NGeiGn2cHP0j8+kjYQ1jM1EHmZJsAOeY41nHCj7UHfSauk+ynOF03 CPMESNDDdXy1TYKKlo8pSkfRDkAqRgy/v8mfltCIVBpUISluxr0R+lPr5jo+Swd+W1J9 NQX6kGqVE9U/YHEXp6OR07XXePtO3LgfuhWZj+IlwsMGFFuAZr28rp8EyiLjt/zuc3gn o840ZI+/OahD/t1rG9fGfgYoGQTMgGHPm5Lm97VcoGEs1gEc/2SRBOh6hY7GkiMZ/+lS MQsA== MIME-Version: 1.0 X-Received: by 10.68.182.165 with SMTP id ef5mr2372654pbc.169.1390407537460; Wed, 22 Jan 2014 08:18:57 -0800 (PST) In-Reply-To: <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> References: <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> Date: Thu, 23 Jan 2014 03:18:57 +1100 Subject: Re: SIngleton from __defaults__ From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1390407541 news.xs4all.nl 2948 [2001:888:2000:d::a6]:50148 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64508 On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las 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