static object

Gabriel Genellina gagsl-py at yahoo.com.ar
Wed Jan 3 19:35:49 EST 2007


At Wednesday 3/1/2007 19:38, meelab wrote:

>I am looking for a way to create a "static object" or a "static class" -
>terms might be inappropriate - having for instance:
>
>class StaticClass:
>     .
>     .
>
>and then
>staticObject1 = StaticClass()
>staticObject2 = StaticClass()
>
>so that staticObject1 and staticObject2 refers exactly to the same
>instance of object.

This is usually known as a Singleton.
If you only want it to store values, or use "normal" methods, the 
most direct way is a simple module - modules are already singletons in Python.
If you want to include properties, descriptors, and such, look for 
the Singleton (or Borg) pattern in the Python Cookbook: 
http://aspn.activestate.com/ASPN/Cookbook/Python/


-- 
Gabriel Genellina
Softlab SRL 


	

	
		
__________________________________________________ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 




More information about the Python-list mailing list