Tool69 a écrit : > Hi, > I've got a simple but difficult problem : > > Suppose I've got a Paper class, on wich I can draw i.e a rectangle, a > circle or whatever. > > class Paper(...): > def __init__(self, paperx, papery): > self.paperx = paperx > self.papery = papery > .... > def draw(self, Primitive_Object): > .... > class Rectangle( ): <--- a Primitive_Object > ... > > Now, inside my Rectangle class, I need to recover the Paper instance > who called it (because I need the paper sizes to calculate something). > I now I can use a global variable, say " _paper" and then, inside my > Paper.__init__() write something like this : > > global _paper > _paper = [paperx,papery] > > But it has drawbacks :
Indeed... > what if I've got several Paper instances ? class Paper(...): > .... def draw(self, drawable): drawable.draw(self) class Rectangle( ): <--- a drawable ... def draw(self, drawing_surface): ... Now consider whether you really need Paper.draw... HTH -- http://mail.python.org/mailman/listinfo/python-list