Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34502
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| 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; 'patterns': 0.04; 'cache': 0.05; 'class,': 0.07; 'used.': 0.07; 'python': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Help': 0.10; 'suggest': 0.11; 'yet.': 0.13; '"use': 0.16; 'instance:': 0.16; 'no-nonsense': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Singleton': 0.16; 'underscores': 0.16; 'wrote:': 0.17; 'config': 0.17; 'instance': 0.17; "shouldn't": 0.17; 'module': 0.19; 'sort': 0.21; 'trying': 0.21; 'import': 0.21; 'example': 0.23; "haven't": 0.23; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'module.': 0.27; 'then.': 0.27; 'options': 0.27; 'header:X-Complaints-To:1': 0.28; 'josh': 0.29; 'trigger': 0.29; 'class': 0.29; 'december': 0.32; 'from:addr:yahoo.co.uk': 0.32; 'morning': 0.32; 'to:addr :python-list': 0.33; 'knowledge': 0.33; 'received:org': 0.36; 'but': 0.36; 'subject:with': 0.36; 'thank': 0.36; 'two': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'skip:o 20': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'first': 0.61; 'mentioned': 0.63; 'more': 0.63; 'therefore': 0.65; 'benefit': 0.70; 'answer.': 0.71; 'saw': 0.75; 'gain': 0.79; 'coffee': 0.84; 'configparser': 0.84; 'otten': 0.84; 'subject:skip:S 10': 0.84; 'anywhere,': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
| Subject | Re: Help with Singleton SafeConfigParser |
| Date | Sat, 08 Dec 2012 20:23:41 +0000 |
| References | <113bded6-c75f-4322-9703-93420b4c3522@googlegroups.com> <mailman.625.1354988369.29569.python-list@python.org> <e33d91bc-cb8f-4414-9f8c-1339cecfc6f5@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Gmane-NNTP-Posting-Host | host-92-22-93-140.as13285.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/17.0 Thunderbird/17.0 |
| In-Reply-To | <e33d91bc-cb8f-4414-9f8c-1339cecfc6f5@googlegroups.com> |
| X-Antivirus | avast! (VPS 121208-0, 08/12/2012), Outbound message |
| X-Antivirus-Status | Clean |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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.630.1354998232.29569.python-list@python.org> (permalink) |
| Lines | 46 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1354998232 news.xs4all.nl 6924 [2001:888:2000:d::a6]:46168 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:34502 |
Show key headers only | View raw
On 08/12/2012 17:48, Josh English wrote:
> On Saturday, December 8, 2012 9:40:07 AM UTC-8, Peter Otten wrote:
>>
>> Two underscores trigger name mangling only in a class, not in a module.
>>
>> Don't try to hide the Options instance:
>>
>> # module config.py
>>
>> import ConfigParser
>>
>> class Options(ConfigParser.SafeConfigParser):
>>
>> ... # as above
>>
>> options = Options()
>>
>> Then use it elsewhere:
>>
>> from config import options
>>
>> options.set("mysection", "myoption", "myvalue")
>>
>> All but the first import will find the module in the cache (sys.modules) and
>>
>> therefore the same Options instance will be used. VoilĂ your no-nonsense
>>
>> singleton.
>
>
> Ah. I was over-thinking again. I couldn't find an example of this anywhere, and when I saw the tirades against Singletons they mentioned "use modules" but, well, I haven't had my morning coffee yet. I shouldn't even be trying this sort of thing until then.
>
> Thank you for the simple answer.
>
> Josh
>
For the benefit of the OP and others, if you want to gain more knowledge
about patterns in Python such as the Singleton, I suggest you use your
favourite search engine to find "Alex Martelli Python patterns".
--
Cheers.
Mark Lawrence.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Help with Singleton SafeConfigParser Josh English <Joshua.R.English@gmail.com> - 2012-12-08 09:11 -0800
Re: Help with Singleton SafeConfigParser Peter Otten <__peter__@web.de> - 2012-12-08 18:40 +0100
Re: Help with Singleton SafeConfigParser Josh English <Joshua.R.English@gmail.com> - 2012-12-08 09:48 -0800
Re: Help with Singleton SafeConfigParser Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-12-08 20:23 +0000
Re: Help with Singleton SafeConfigParser Josh English <Joshua.R.English@gmail.com> - 2012-12-08 09:48 -0800
csiph-web