python 2.1 singleton
Duncan Booth
duncan at NOSPAMrcp.co.uk
Wed Oct 15 05:18:37 EDT 2003
"Alexiev Nikolay" <alexiev at activesolutions.bg> wrote in
news:mailman.112.1066205794.2192.python-list at python.org:
> I need a simple implementation of singleton that will work on python
> 2.1. I havn't got idea how to creat without staticmethod. Can you give
> me a solution ??? 10x in advance
>
The simplest singleton implementation, which works for any version of
Python is simply to use a module as your singleton instead of a class. You
can get hold of the singleton object from anywhere simply by importing it.
All functions defined in a module are effectively static methods on the
module object.
--
Duncan Booth duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
More information about the Python-list
mailing list