Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python': 0.08; '>>>>': 0.09; 'am,': 0.12; 'win32': 0.12; 'def': 0.13; '"copyright",': 0.16; '"credits"': 0.16; '"license"': 0.16; '--rich': 0.16; 'foo(object):': 0.16; 'from:addr:noir.com': 0.16; 'from:addr:rich': 0.16; 'message-id:@noir.com': 0.16; 'received:198.144': 0.16; 'received:198.144.209': 0.16; 'received:198.144.209.5': 0.16; 'received:noir.com': 0.16; 'recognizing': 0.16; 'singleton': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; '3.2': 0.18; 'cc:no real name:2**0': 0.20; 'dec': 0.22; 'feb': 0.22; 'header:In-Reply-To:1': 0.22; 'cc:2**0': 0.24; 'work,': 0.26; 'raise': 0.28; 'bit': 0.28; '27,': 0.29; 'cc:addr:python.org': 0.29; 'class': 0.29; 'kelly': 0.30; 'object.': 0.30; 'received:198': 0.32; 'tue,': 0.32; 'header:User- Agent:1': 0.33; 'actually': 0.33; 'rather': 0.33; 'it.': 0.34; 'richard': 0.34; 'try:': 0.34; '...': 0.36; 'received:192': 0.37; 'think': 0.37; 'skip:_ 10': 0.37; 'being': 0.39; 'received:192.168': 0.40; 'more': 0.61; 'type': 0.61; '2011': 0.61; 'ever': 0.65; 'conceptual': 0.67; '10:28': 0.84; 'received:192.168.1.7': 0.84 Date: Tue, 27 Dec 2011 12:31:10 -0800 From: K Richard Pixley User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: Ian Kelly Subject: Re: confused about __new__ References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1325018213 news.xs4all.nl 6964 [2001:888:2000:d::a6]:52882 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18051 On 12/27/11 10:28 , Ian Kelly wrote: > On Tue, Dec 27, 2011 at 10:41 AM, K Richard Pixley wrote: >> The conceptual leap for me was in recognizing that a class is just an >> object. The best way, (imo, so far), to create a singleton in python is to >> use the class itself as the singleton rather than ever instantiating it. >> With a little work, you can even prevent it from ever being instantiated. > I don't think that's actually possible: > > Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> class Foo: > ... def __new__(cls): > ... raise TypeError > ... def __init__(self): > ... raise TypeError > ... >>>> type(object.__new__(Foo)) > Try: class Foo(object): def __new__(cls): return cls --rich