2007/11/6, Donn Ingle <[EMAIL PROTECTED]>:
> Hi,
> I'm doing something odd with pycairo and friends and I want to see what
> commands are coming out of my objects.
>
> Here's some code:
>
> class Box:
> def draw()
> self.context.set_source_rgb(1, 0, 0)
> self.context.rectangle(0, 00, 50, 50)
> self.context.fill()
>
> Box.draw() draws a red box, all fine. But, I *also* want it to output the
> actual commands within the draw def to the console (or a file).
>
> At the moment I am doing this:
> class Box:
> def draw()
> self.context.set_source_rgb(1, 0, 0)
> self.context.rectangle(0, 00, 50, 50)
> self.context.fill()
> print """
> self.context.set_source_rgb(1, 0, 0)
> self.context.rectangle(0, 00, 50, 50)
> self.context.fill()
> """
> Do you see the form? Is there some <voodoo magic> python introspection way I
> can perform that automagically without having to use the print statement?
>
> Something like:
> class Box:
> def draw()
> self.context.set_source_rgb(1, 0, 0)
> self.context.rectangle(0, 00, 50, 50)
> self.context.fill()
> def dump():
> <mystical mindblowing stuff involving deep magic>
You could use inspect, something like this:
import inspect
class Box:
def draw(self):
print "hi"
return 3
x = Box()
print inspect.getsource(x.draw)
--
-- Guilherme H. Polo Goncalves
--
http://mail.python.org/mailman/listinfo/python-list