Singleton and C extensions

Emmanuel Briot briot at nospam.fr.invalid
Fri Nov 25 08:08:13 EST 2005


I am participating in the development of a GPL IDE
   https://libre2.adacore.com/gps/

It is written in Ada, but provides an extensive extensibility through
Python.

I am not really good at python, but I was trying to implement the
singleton design pattern in C, so that for instance calling the constructor

   ed = Editor ("foo")

would either return an existing instance of Editor currently editing
"foo", or would create a new instance. Basically, one python instance is
stored inside each of the visual windows representing an editor, and I
want to get that instance if it already exists, instead of creating a
new one each time.

I basically would like
    ed = Editor ("foo")
    ed.attribute = "whatever"
    print Editor ("foo").attribute

to print "whatever"


Has any one an example on how to do that in C, or maybe even at the
python level itself, and I will try to adapt it ?

Thanks in advance

Emmanuel



More information about the Python-list mailing list