Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #59497

Re: Implementing #define macros similar to C on python

References <fae7479b-ecec-4114-9750-6595fa8c78fa@googlegroups.com>
Date 2013-11-15 14:49 +1100
Subject Re: Implementing #define macros similar to C on python
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2636.1384487396.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Nov 15, 2013 at 1:29 PM, JL <lightaiyee@gmail.com> 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
>
> #ifdef DEBUG_ENABLE
> DEBUG_PRINT   print
> #else
> DEBUG_PRINT
>
> 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
else:
    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.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Implementing #define macros similar to C on python JL <lightaiyee@gmail.com> - 2013-11-14 18:29 -0800
  Re: Implementing #define macros similar to C on python Dave Angel <davea@davea.name> - 2013-11-14 21:30 -0600
  Re: Implementing #define macros similar to C on python Chris Angelico <rosuav@gmail.com> - 2013-11-15 14:49 +1100
    Re: Implementing #define macros similar to C on python JL <lightaiyee@gmail.com> - 2013-11-15 15:36 -0800
      Re: Implementing #define macros similar to C on python Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2013-11-16 01:20 +0100
      Re: Implementing #define macros similar to C on python Terry Reedy <tjreedy@udel.edu> - 2013-11-15 19:22 -0500
      Re: Implementing #define macros similar to C on python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-16 00:22 +0000
        Re: Implementing #define macros similar to C on python JL <lightaiyee@gmail.com> - 2013-11-15 21:38 -0800
          Re: Implementing #define macros similar to C on python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-16 11:48 +0000
  Re: Implementing #define macros similar to C on python Roy Smith <roy@panix.com> - 2013-11-14 23:10 -0500
    Re: Implementing #define macros similar to C on python Chris Angelico <rosuav@gmail.com> - 2013-11-15 15:57 +1100
    Re: Implementing #define macros similar to C on python Serhiy Storchaka <storchaka@gmail.com> - 2013-11-16 12:02 +0200
  Re: Implementing #define macros similar to C on python Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2013-11-16 00:20 +0100

csiph-web