Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > tracing function calls

Reply
Thread Tools

tracing function calls

 
 
Stormbringer
Guest
Posts: n/a
 
      04-23-2005
Greetings,

I've been wondering if there is a mechanism similar to trace/untrace
found in lisp, for example call trace(function-name) and whenever this
function is called it will show its parameters to stdout ....

 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      04-23-2005
"Stormbringer" wrote:

> I've been wondering if there is a mechanism similar to trace/untrace
> found in lisp, for example call trace(function-name) and whenever this
> function is called it will show its parameters to stdout ....


def trace(func):
def tracer(*args, **kwargs):
print func.__name__, args, kwargs
result = func(*args, **kwargs)
print func.__name__, "return", result
return result
return tracer

def myfunc(a, b, c):
return a + b + c

myfunc = trace(myfunc)

myfunc(1, 2, 3)

(tweak as necessary)

</F>

 
Reply With Quote
 
 
 
 
Stormbringer
Guest
Posts: n/a
 
      04-23-2005
Thank you Fredrik !
With a little tweaking for the right indentation it should prove useful


Fredrik Lundh wrote:
> "Stormbringer" wrote:
>
> > I've been wondering if there is a mechanism similar to

trace/untrace
> > found in lisp, for example call trace(function-name) and whenever

this
> > function is called it will show its parameters to stdout ....

>
> def trace(func):
> def tracer(*args, **kwargs):
> print func.__name__, args, kwargs
> result = func(*args, **kwargs)
> print func.__name__, "return", result
> return result
> return tracer
>
> def myfunc(a, b, c):
> return a + b + c
>
> myfunc = trace(myfunc)
>
> myfunc(1, 2, 3)
>
> (tweak as necessary)
>
> </F>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function tracing jimocz C++ 2 07-27-2008 08:17 PM
This function has an onClick event that calls a function that calls This function Bob Javascript 5 10-24-2006 04:11 PM
[Publication] [About] Tracing Anonymouse P2P VoIP Calls on the Internet GNUEMAIL-Postmaster UK VOIP 0 08-25-2006 03:43 PM
Tracing Web service calls magennisw@etrade.com.au ASP .Net 4 05-29-2006 11:13 AM
How override ALL function calls? (Is there a "function call function"?) seberino@spawar.navy.mil Python 2 08-01-2005 12:38 PM



Advertisments