Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34496
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <Joshua.R.English@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'cache': 0.05; 'class,': 0.07; 'used.': 0.07; 'to:addr:comp.lang.python': 0.09; 'cc:addr :python-list': 0.10; 'subject:Help': 0.10; 'yet.': 0.13; '"use': 0.16; 'instance:': 0.16; 'no-nonsense': 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; 'cc:2**0': 0.23; 'example': 0.23; "haven't": 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'module.': 0.27; 'then.': 0.27; 'options': 0.27; 'josh': 0.29; 'trigger': 0.29; 'class': 0.29; 'december': 0.32; 'morning': 0.32; 'received:google.com': 0.34; 'received:209.85': 0.35; 'but': 0.36; 'subject:with': 0.36; 'thank': 0.36; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'your': 0.60; 'first': 0.61; 'mentioned': 0.63; 'therefore': 0.65; 'answer.': 0.71; 'saw': 0.75; 'coffee': 0.84; 'configparser': 0.84; 'otten': 0.84; 'subject:skip:S 10': 0.84; 'anywhere,': 0.93 |
| Newsgroups | comp.lang.python |
| Date | Sat, 8 Dec 2012 09:48:04 -0800 (PST) |
| In-Reply-To | <mailman.625.1354988369.29569.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=216.99.216.115; posting-account=yMP7kQoAAAAXsyJyvL-3qYVslbdYOSQP |
| References | <113bded6-c75f-4322-9703-93420b4c3522@googlegroups.com> <mailman.625.1354988369.29569.python-list@python.org> |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| X-Google-IP | 216.99.216.115 |
| MIME-Version | 1.0 |
| Subject | Re: Help with Singleton SafeConfigParser |
| From | Josh English <Joshua.R.English@gmail.com> |
| To | comp.lang.python@googlegroups.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.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> |
| Message-ID | <mailman.626.1354988895.29569.python-list@python.org> (permalink) |
| Lines | 52 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1354988895 news.xs4all.nl 6958 [2001:888:2000:d::a6]:48001 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:34496 |
Show key headers only | View raw
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
Back to comp.lang.python | Previous | Next — Previous 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