From: Juha-Matti T. <jm...@pu...> - 2002-01-03 00:36:02
|
On ke, 2002-01-02 at 02:28, Grzegorz Adam Hankiewicz wrote: > I seem to have overlooked global variables wrapping > standard procedures. IOW: how the hell do you wrap around something > like say mouse_x? > > My little understanding tells me that you would create a python wrapper > class. User python code would use methods of this class like set/get > to write/read the variable, and the class code would do the actual trick > of modifying/returning the real C global value. Python example: I have a hunch that there is some way to wrap a variable. Perhaps by creating a new type. But the class method is propably a cleaner way to wrap that. > import pyallegro > pyallegro.install() > pyallegro.whatever() > print "Mouse is at %d" % pyallegro.mouse_x.get() I think a better style (similar to what's done in python-gnome) would be this: import alpy alpy.init() alpy.whatever() print "Mouse is at %d" % alpy.mouse.x Here the __getattr__-method could be defined for a class 'mouse'. See the syntax from http://www.python.org/doc/current/ref/attribute-access.html#l2h-110 Still I don't know if this can be applied at the module-level. -- Juha-Matti Tapio, ATK-suunnittelija, fil. yo. +358-50-5419230 |