static object

meelab meelab at free.fr
Wed Jan 3 17:38:35 EST 2007


Dear All,

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.

In other words, that is a class which would result in only 1 instance
always the same no matter how many times I will "instantiate" it.

My purpose is to permit this class to initialize a massive amount of
data that I need to access from different points of my program without
duplicating this data in memory and without loosing time in reloading it
 each time I need it.

I noticed the staticmethods, and the __new__ method which could , but I
always get stuck in actually creating static DATA without having global
data.

Does anyone have a start of a clue to this ?

Many thanks in advance

Emmanuel.



More information about the Python-list mailing list