any macro-like construct/technique/trick?
- From: "Mac" <idontneednostinkinid@xxxxxxxxx>
- Date: 1 Jun 2005 15:37:01 -0700
Is there a way to mimic the behaviour of C/C++'s preprocessor for
macros? The problem: a lot of code like this:
def foo():
# .... do some stuff
if debug:
emit_dbg_obj(DbgObjFoo(a,b,c))
# .... do more stuff
if debug:
emit_dbg_obj(DbgObjBar(d,e))
# ... and so on ...
Notes:
* the two-lines of debug conditional tend to really break up the flow
of the surrounding code
* in C you could wrap them with a macro so you could do
DEBUG_EMIT(DbgObjFoo(a,b,c)), etc, with the macro only instantiating
the object and processing it if the debug flag was set. The one-liner
is MUCH less disruptive visually when reading code
* using
def debug_emit(obj):
if debug:
emit_dbg_obj(obj)
is a poor solution, because it *always* instantiates DbgObj*, even when
not needed; I want to avoid such unnecessary waste
.
- Follow-Ups:
- Re: any macro-like construct/technique/trick?
- From: Kay Schluehr
- Re: any macro-like construct/technique/trick?
- From: Roy Smith
- Re: any macro-like construct/technique/trick?
- From: Georges JEGO
- Re: any macro-like construct/technique/trick?
- From: Paddy
- Re: any macro-like construct/technique/trick?
- From: alex23
- Re: any macro-like construct/technique/trick?
- From: Andrew Dalke
- Re: any macro-like construct/technique/trick?
- From: Jordan Rastrick
- Re: any macro-like construct/technique/trick?
- Prev by Date: Re: scripting browsers from Python
- Next by Date: Re: BUG pythonw vs subprocess
- Previous by thread: help with extending python
- Next by thread: Re: any macro-like construct/technique/trick?
- Index(es):
Relevant Pages
|