Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86645
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <torriem+gmail@torriefamily.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.015 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'python,': 0.02; 'essentially': 0.04; '*is*': 0.09; 'way:': 0.09; 'python': 0.11; '"could': 0.16; 'constructor.': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'guessing': 0.16; 'singleton': 0.16; 'subject:?)': 0.16; 'top-level': 0.16; 'wrote:': 0.18; 'module': 0.19; 'meant': 0.20; 'thanks.': 0.20; 'import': 0.22; 'header:User-Agent:1': 0.23; 'config': 0.24; "haven't": 0.24; 'class.': 0.26; 'header:In-Reply-To:1': 0.27; 'feature': 0.29; "i'm": 0.30; 'code': 0.31; 'commonly': 0.31; 'maintains': 0.31; 'once,': 0.31; 'class': 0.32; 'run': 0.32; 'another': 0.32; 'implemented': 0.33; 'not.': 0.33; 'could': 0.34; 'problem': 0.35; 'subject: (': 0.35; 'created': 0.35; 'but': 0.35; 'module.': 0.36; 'should': 0.36; 'clear': 0.37; 'sometimes': 0.38; 'message- id:@gmail.com': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'little': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'tell': 0.60; 'new': 0.61; 'first': 0.61; 'such': 0.63; 'more': 0.64; 'charset:windows-1252': 0.65; 'between': 0.67; 'sharing': 0.69; 'acts': 0.74; '(global': 0.84; 'state.': 0.95 |
| X-Virus-Scanned | amavisd-new at torriefamily.org |
| Date | Sat, 28 Feb 2015 22:05:16 -0700 |
| From | Michael Torrie <torriem@gmail.com> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: suggestions for functional style (singleton pattern?) |
| References | <WXrIw.14066$uP4.9692@fx20.iad> <13v4falb4odnhtvss4qdatnn16sgiv5pgd@4ax.com> <jAwIw.631640$rq4.16649@fx27.iad> |
| In-Reply-To | <jAwIw.631640$rq4.16649@fx27.iad> |
| Content-Type | text/plain; charset=windows-1252 |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.19 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2.1425186322.29956.python-list@python.org> (permalink) |
| Lines | 25 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1425186322 news.xs4all.nl 2945 [2001:888:2000:d::a6]:39813 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:86645 |
Show key headers only | View raw
On 02/28/2015 09:29 PM, yves@zioup.com wrote: >> Problem 4: >> You speak of a singleton. But you haven't implemented one. It is not >> clear from your code if this class should be a singleton. I'm guessing >> not. Singletons are in fact rare. Well, let me put it another way: >> Good reasons to code a singleton are rare. > > Thanks. I hadn't realise "singleton" meant a class built such that it could > not be instanciated more than once, I thought it corresponded to a pattern > where only one object is ever created from a given class. Is not "only one object is ever created from a given class" the same as "could not be [instantiated] more than once?" To be clear, singletons are commonly used in Python every time you import a module. A module *is* a singleton pattern, particularly one that maintains state. I use sometimes use this feature for sharing config and other data between other modules (global state when it's required). "import module" essentially does the one-time instantiation if it's a new import; top-level code in the module is run once on first import, where it acts like a constructor. So it functions as a singleton. As near as I can tell there's very little reason to make a class-based singleton in Python, since a module has the same effect and is cleaner.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
suggestions for functional style (singleton pattern?) yves@zioup.com - 2015-02-28 16:12 -0700
Re: suggestions for functional style (singleton pattern?) Michael Torrie <torriem@gmail.com> - 2015-02-28 19:19 -0700
Re: suggestions for functional style (singleton pattern?) yves@zioup.com - 2015-02-28 21:11 -0700
Re: suggestions for functional style (singleton pattern?) Michael Torrie <torriem@gmail.com> - 2015-02-28 22:14 -0700
Re: suggestions for functional style (singleton pattern?) Mario Figueiredo <marfig@gmail.com> - 2015-03-01 04:45 +0100
Re: suggestions for functional style (singleton pattern?) yves@zioup.com - 2015-02-28 21:29 -0700
Re: suggestions for functional style (singleton pattern?) Michael Torrie <torriem@gmail.com> - 2015-02-28 22:05 -0700
Re: suggestions for functional style (singleton pattern?) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-02 02:55 +1100
Re: suggestions for functional style (singleton pattern?) Fabien <fabien.maussion@gmail.com> - 2015-03-02 11:19 +0100
Re: suggestions for functional style (singleton pattern?) Mario Figueiredo <marfig@gmail.com> - 2015-03-02 11:31 +0100
Re: suggestions for functional style (singleton pattern?) Michael Torrie <torriem@gmail.com> - 2015-03-02 08:59 -0700
Re: suggestions for functional style (singleton pattern?) Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-02 09:51 -0700
Re: suggestions for functional style (singleton pattern?) Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-03-01 19:00 +1300
Re: suggestions for functional style (singleton pattern?) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-02 02:04 +1100
Re: suggestions for functional style (singleton pattern?) Mario Figueiredo <marfig@gmail.com> - 2015-03-01 19:20 +0100
Re: suggestions for functional style (singleton pattern?) Paul Rubin <no.email@nospam.invalid> - 2015-02-28 22:23 -0800
csiph-web