Implementing #define macros similar to C on python

Chris Angelico rosuav at
Fri Nov 15 04:49:52 CET 2013

On Fri, Nov 15, 2013 at 1:29 PM, JL <lightaiyee at> wrote:
> One of my favorite tools in C/C++ language is the preprocessor macros.
> One example is switching certain print messages for debugging use only
> DEBUG_PRINT   print
> #else
> Is it possible to implement something similar in python? Thank you.

There are usually other ways to do things. For instance, you can
define a function to either do something or do nothing:

if debug_mode:
    debug_print = print
    debug_print = lambda: None

debug_print("This won't be shown unless we're in debug mode!")

But as Dave says, you could write a preprocessor if you need one.


More information about the Python-list mailing list