Howto MACRO in python ?

Bill Loren lorenb2 at
Tue Aug 12 14:28:31 CEST 2003

Welp, I'm trying to implement some kind of tracing mechanism which will
announce every function entrance
in Run-Time.
I wrote a trace function:


def trace(level, message):
    if DEBUG_LVL >= level:
        print message

to which I will call with:

trace(40, "%s.%s: entrance" % (__name__, <function_name>) )

upon every function entrance.
(btw I couldn't find any built-in name which correspands to the current
function name so
 I type it myslef every trace call)

my wish was to create a MACRO that will save me some text in the code.
something like:
TRACE(40, "entrance")

that will expand into the trace call.

what do you think ?

thanks so much !

----- Original Message -----
From: "Peter Hansen" <peter at>
Newsgroups: comp.lang.python
To: <python-list at>
Sent: Tuesday, August 12, 2003 1:32 PM
Subject: Re: Howto MACRO in python ?

> Bill Loren wrote:
> >
> > I was looking for a guidance about how to code MACROs in python.
> > any offer ?
> A few alternative responses to Irmen's to-the-point answer:
> 1. Nobody does.
> 2. Those who do, probably use a macro language, like maybe M4.
> 3. Nobody does.
> 4. What are you actually trying to accomplish, specifically?
> -Peter
> --

More information about the Python-list mailing list