Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'debug': 0.07; 'debugging': 0.07; '#else': 0.16; '#ifdef': 0.16; 'c/c++': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'lambda:': 0.16; 'macros.': 0.16; 'subject:python': 0.16; 'language': 0.16; 'wrote:': 0.18; 'things.': 0.19; 'example': 0.22; 'python?': 0.22; 'print': 0.22; 'instance,': 0.24; '15,': 0.26; 'define': 0.26; 'shown': 0.26; 'certain': 0.27; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'message-id:@mail.gmail.com': 0.30; 'usually': 0.31; "we're": 0.32; 'fri,': 0.33; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'possible': 0.36; 'similar': 0.36; 'implement': 0.38; 'thank': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'dave': 0.60; 'you.': 0.62; 'subject: #': 0.96; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=MVpHfDz4IWD9pgboZx8CwQGWsyHRlN7Fk3v+W+sRXJk=; b=jN6l8aObOwz74pzvGXClfUS4NdOb0GgKhsRdwgJfC2WzirtIe85IUUA5uuP4RsT8rn RENo+I+ctqHgkMJiZBwc3bzHhQmhX9NZjba3U3OsjrcxkNigOdY6C8XIHIac/DTwtjUA nfefxPuFAiabU9O/HKAs9RmypBQEJADZCxt5Phl+wXGAZHdGcVfZ75kJDaGHg4IlT4Up FBZ4KgsXDgOP+WZa7ZOL3SeXYOoRiltQDrnN78oSMXBjJS5+W7yD45ug6z0SKNDEwgBf /03OTdrS8XHpE2JvbpkmP0xJhMLWLI/OhuReg7Hv7eUztcosLeaMiXUj32rkR1006eJa i2Xg== MIME-Version: 1.0 X-Received: by 10.68.203.234 with SMTP id kt10mr4809281pbc.114.1384487393024; Thu, 14 Nov 2013 19:49:53 -0800 (PST) In-Reply-To: References: Date: Fri, 15 Nov 2013 14:49:52 +1100 Subject: Re: Implementing #define macros similar to C on python From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1384487396 news.xs4all.nl 15910 [2001:888:2000:d::a6]:44345 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:59497 On Fri, Nov 15, 2013 at 1:29 PM, JL 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