Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ethan Furman Newsgroups: comp.lang.python Subject: Re: Clean Singleton Docstrings Date: Fri, 08 Jul 2016 13:00:01 -0700 Lines: 35 Message-ID: References: <2EB2D06F-46A1-4812-A91B-1D2A31440EA6@gmail.com> <57800641.3050904@stoneleaf.us> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de uGQAtH3BWBXGSIfd2PHu4w00HMLQzVkAogIKde9O3r0w== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'preferably': 0.05; 'sys': 0.05; 'dict': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'key)': 0.09; 'message-id:@stoneleaf.us': 0.09; 'newly': 0.09; 'importable': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'registery': 0.16; 'registry': 0.16; 'subject:Singleton': 0.16; 'using,': 0.16; 'wrote:': 0.16; 'instance,': 0.18; 'gui': 0.18; '>>>': 0.20; 'enforce': 0.22; 'am,': 0.23; 'elements': 0.23; 'insert': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; "i've": 0.25; 'header:User-Agent:1': 0.26; 'connected': 0.27; 'object,': 0.27; '~ethan~': 0.29; 'allows': 0.30; 'work.': 0.30; 'michael': 0.33; 'gets': 0.35; 'skip:. 20': 0.35; 'something': 0.35; 'should': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'method': 0.37; 'things': 0.38; 'data': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'your': 0.60; 'share': 0.61; 'provide': 0.61; 'show': 0.62; 'charset:windows-1252': 0.62; 'skip:n 10': 0.62; 'needing': 0.63; 'information': 0.63; 'benefit': 0.66; 'jul': 0.72; 'state.': 0.72; 'updated,': 0.84; 'anywhere,': 0.93; 'device.': 0.93 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <57800641.3050904@stoneleaf.us> X-Mailman-Original-References: <2EB2D06F-46A1-4812-A91B-1D2A31440EA6@gmail.com> Xref: csiph.com comp.lang.python:111208 On 07/08/2016 09:57 AM, Rob Gaddi wrote: > Michael Selik wrote: >> On Jul 7, 2016, at 7:46 PM, Rob Gaddi wrote: >>> I've got a package that contains a global ensmartened dict that allows >>> all the various parts of my program to share state. >> >> The simplest solution would be to use a module as your singleton. For example, "registry.py" would work. Pydoc will show its docstring, and it will have all the features you had been using, with the added benefit of not needing to enforce its singletonness. >> > > REALLY needs to be an object, preferably dict-like. For instance, one > of the things it does is provide a .getKeyChanged(self, key) method that > returns a keyChanged QSignal so that various elements of the program can > all register for notifications triggered by __setitem__. That way, when > Registry['dut'] gets updated, all of the various GUI elements reliant on > information about the dut all dump their old data and find out about the > newly connected device. Get the best of both worlds -- insert your Registry object into sys.modules. It is then importable from anywhere, yet still has all its native object power. Something like this should do the trick: # untested import sys sys.modules['%s.registry' % __name__] = _Register() and then elsewhere: from blah import registery registry.whatever() -- ~Ethan~