Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18050
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ian.g.kelly@gmail.com> |
| 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; 'python': 0.08; 'am,': 0.12; 'win32': 0.12; 'def': 0.13; '"copyright",': 0.16; '"credits"': 0.16; '"license"': 0.16; 'foo(object):': 0.16; 'it..': 0.16; 'recognizing': 0.16; 'singleton': 0.16; '\xa0def': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; '>>>': 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; 'message-id:@mail.gmail.com': 0.28; '27,': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'class': 0.29; 'kelly': 0.30; 'object.': 0.30; 'tue,': 0.32; 'actually': 0.33; 'rather': 0.33; 'richard': 0.34; 'received:209.85.212': 0.34; 'try:': 0.34; '...': 0.36; 'received:google.com': 0.37; 'think': 0.37; 'skip:_ 10': 0.37; 'received:209.85': 0.38; 'being': 0.39; 'received:209': 0.40; 'more': 0.61; 'type': 0.61; '2011': 0.61; 'ever': 0.65; 'conceptual': 0.67; '10:28': 0.84; 'to:addr:rich': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=16L2QbqQSvbjoqmv7h4fubsD90TqYi5AetVcAXTiB84=; b=vNcJmPheeEetiFEk4Bw0YwzZ7dahOfdvkv4Oash8D53oi/Jf5HWZ1OJ0md3uIZx1RU u7gBu/0SYJYeXvJcnwjrXW1lFkj0CVpgZjlW+cZokXfB0//Dpb0byiBGRA3/Ew9NuZMC YFbFM6/kkKJvnWf8pWLESms1Fb2rvAbT71fvQ= |
| MIME-Version | 1.0 |
| In-Reply-To | <4EFA2B0E.2000506@noir.com> |
| References | <MPbKq.47607$cN1.25052@newsfe12.iad> <mailman.4125.1324964928.27778.python-list@python.org> <ErnKq.40489$2e7.4368@newsfe18.iad> <CALwzidm_jc883ShOSmRe7N+5mx6uyKp_eSGvGBJNQOFy46xozA@mail.gmail.com> <4EFA2B0E.2000506@noir.com> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Tue, 27 Dec 2011 13:34:08 -0700 |
| Subject | Re: confused about __new__ |
| To | K Richard Pixley <rich@noir.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| 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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4149.1325018086.27778.python-list@python.org> (permalink) |
| Lines | 56 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1325018086 news.xs4all.nl 6972 [2001:888:2000:d::a6]:47333 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:18050 |
Show key headers only | View raw
On Tue, Dec 27, 2011 at 1:31 PM, K Richard Pixley <rich@noir.com> wrote: > On 12/27/11 10:28 , Ian Kelly wrote: >> >> On Tue, Dec 27, 2011 at 10:41 AM, K Richard Pixley<rich@noir.com> 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)) >> >> <class '__main__.Foo'> > > > Try: > > class Foo(object): > def __new__(cls): > return cls Okay: 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): ... return cls ... >>> f1 = object.__new__(Foo) >>> f2 = object.__new__(Foo) >>> type(f1), type(f2) (<class '__main__.Foo'>, <class '__main__.Foo'>) >>> f1 is f2 False
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
confused about __new__ "K. Richard Pixley" <rich@noir.com> - 2011-12-26 20:28 -0800
Re: confused about __new__ Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-27 04:53 +0000
Re: confused about __new__ K Richard Pixley <rich@noir.com> - 2011-12-26 21:27 -0800
Re: confused about __new__ Fredrik Tolf <fredrik@dolda2000.com> - 2011-12-27 06:48 +0100
Re: confused about __new__ K Richard Pixley <rich@noir.com> - 2011-12-27 09:41 -0800
Re: confused about __new__ Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-27 11:28 -0700
Re: confused about __new__ Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-27 13:34 -0700
Re: confused about __new__ K Richard Pixley <rich@noir.com> - 2011-12-27 14:19 -0800
Re: confused about __new__ Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-27 15:43 -0700
Re: confused about __new__ K Richard Pixley <rich@noir.com> - 2011-12-27 12:31 -0800
Re: confused about __new__ Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-27 00:28 -0700
Re: confused about __new__ Lie Ryan <lie.1296@gmail.com> - 2011-12-27 18:47 +1100
Re: confused about __new__ Fredrik Tolf <fredrik@dolda2000.com> - 2011-12-27 19:05 +0100
csiph-web