Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29873

Java singletonMap in Python

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 <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.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 <breamoreboy@yahoo.co.uk>
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 <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.1165.1348442059.27098.python-list@python.org> (permalink)
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

Show key headers only | View raw


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.


Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Java singletonMap in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-24 00:14 +0100
  Re: Java singletonMap in Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-24 02:20 +0000
    Re: Java singletonMap in Python Duncan Booth <duncan.booth@invalid.invalid> - 2012-09-24 17:33 +0000
      Re: Java singletonMap in Python 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-24 12:03 -0700
      Re: Java singletonMap in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-24 20:28 +0100
      Re: Java singletonMap in Python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-25 00:29 -0400
      Re: Java singletonMap in Python Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-25 00:38 -0400

csiph-web