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


Groups > comp.lang.python > #29873

Java singletonMap in Python

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Java singletonMap in Python
Date 2012-09-24 00:14 +0100
Newsgroups comp.lang.python
Message-ID <mailman.1165.1348442059.27098.python-list@python.org> (permalink)

Show all headers | 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