Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.05; 'python': 0.09; 'immutable': 0.09; 'porting': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'url:activestate': 0.09; 'dictionaries': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'recipes': 0.16; 'subject:Java': 0.16; 'url:java': 0.16; 'alex': 0.17; 'latter': 0.22; "i've": 0.23; 'second': 0.24; 'header:User- Agent:1': 0.26; 'wondering': 0.26; '[1]': 0.27; 'possibly': 0.27; '[2]': 0.27; 'header:X-Complaints-To:1': 0.28; 'loads': 0.29; 'waters': 0.29; 'url:code': 0.29; 'probably': 0.29; "i'm": 0.29; 'code': 0.31; 'from:addr:yahoo.co.uk': 0.32; 'curious': 0.33; 'to:addr:python-list': 0.33; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'mark': 0.38; 'some': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'most': 0.61; 'first': 0.61; 'night': 0.62; 'fun': 0.64; 'url:4': 0.72; 'prize': 0.78; 'url:api': 0.84; 'received:2': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Java singletonMap in Python Date: Mon, 24 Sep 2012 00:14:23 +0100 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-2-97-77-28.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 X-Antivirus: avast! (VPS 120923-1, 23/09/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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348442059 news.xs4all.nl 6916 [2001:888:2000:d::a6]:44226 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29873 Purely for fun I've been porting some code to Python and came across the singletonMap[1]. I'm aware that there are loads of recipes on the web for both singletons e.g.[2] and immutable dictionaries e.g.[3]. I was wondering how to combine any of the recipes to produce the best implementation, where to me best means cleanest and hence most maintainable. I then managed to muddy the waters for myself by recalling the Alex Martelli Borg pattern[4]. Possibly or even probably the latter is irrelevant, but I'm still curious to know how you'd code this beast. First prize for the best solution is a night out with me, no guesses what the second prize is :) [1]http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Collections.html [2]http://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons-in-python [3]http://code.activestate.com/recipes/498072-implementing-an-immutable-dictionary/ [4]http://code.activestate.com/recipes/66531-singleton-we-dont-need-no-stinkin-singleton-the-bo/ -- Cheers. Mark Lawrence.