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: 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: 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> 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: 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 On Saturday, December 8, 2012 9:40:07 AM UTC-8, Peter Otten wrote: >=20 >=20 >=20 > Two underscores trigger name mangling only in a class, not in a module.= =20 >=20 > Don't try to hide the Options instance: >=20 >=20 >=20 > # module config.py >=20 > import ConfigParser >=20 >=20 >=20 > class Options(ConfigParser.SafeConfigParser): >=20 > ... # as above >=20 >=20 >=20 > options =3D Options() >=20 >=20 >=20 > Then use it elsewhere: >=20 > from config import options >=20 > options.set("mysection", "myoption", "myvalue") >=20 >=20 >=20 > All but the first import will find the module in the cache (sys.modules) = and=20 >=20 > therefore the same Options instance will be used. Voil=E0 your no-nonsens= e=20 >=20 > 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