Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #59578
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'from:addr:yahoo.co.uk': 0.04; 'assign': 0.07; 'debug': 0.07; 'debugging': 0.07; 'friday,': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tismer': 0.09; 'python': 0.11; '#else': 0.16; '#ifdef': 0.16; '__future__': 0.16; 'c/c++': 0.16; 'lambda:': 0.16; 'macros.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'spacing': 0.16; 'subject:python': 0.16; 'prevent': 0.16; 'language': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'variable': 0.18; 'things.': 0.19; 'thanks.': 0.20; '>>>': 0.22; 'example': 0.22; 'programming': 0.22; 'import': 0.22; 'python?': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'instance,': 0.24; 'url:moin': 0.24; '15,': 0.26; 'define': 0.26; 'shown': 0.26; 'second': 0.26; 'certain': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'statement': 0.30; 'work.': 0.31; 'code': 0.31; 'url:wiki': 0.31; 'usually': 0.31; 'post.': 0.31; 'thanks!': 0.32; "we're": 0.32; 'url:python': 0.33; 'fri,': 0.33; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'possible': 0.36; 'similar': 0.36; 'url:org': 0.36; 'should': 0.36; 'christian': 0.38; 'implement': 0.38; 'thank': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'enough': 0.39; 'either': 0.39; 'received:org': 0.40; 'read': 0.60; 'above,': 0.60; 'dave': 0.60; 'world.': 0.61; 'you.': 0.62; 'kind': 0.63; 'yes': 0.68; 'received:2': 0.84; 'subject: #': 0.96; '2013': 0.98 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
| Subject | Re: Implementing #define macros similar to C on python |
| Date | Sat, 16 Nov 2013 00:22:25 +0000 |
| References | <fae7479b-ecec-4114-9750-6595fa8c78fa@googlegroups.com> <mailman.2636.1384487396.18130.python-list@python.org> <69e7aee9-ad78-412e-9e1c-84b5a855acc9@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | host-2-98-196-224.as13285.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 |
| In-Reply-To | <69e7aee9-ad78-412e-9e1c-84b5a855acc9@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2693.1384561357.18130.python-list@python.org> (permalink) |
| Lines | 75 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1384561357 news.xs4all.nl 15913 [2001:888:2000:d::a6]:37968 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:59578 |
Show key headers only | View raw
On 15/11/2013 23:36, JL wrote:
> Thanks! This is the answer which I am seeking. However, I am not able to get the following line to work. I am using python 2.7.5
>
> debug_print = print
>
> Can we assign a function into a variable in this manner?
>
> On Friday, November 15, 2013 11:49:52 AM UTC+8, Chris Angelico wrote:
>> 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
Yes but please don't top post. Actually print is a statement in Python
2 so your code should work if you use
from __future__ import print_function
at the top of your code.
Would you also be kind enough to read and action this
https://wiki.python.org/moin/GoogleGroupsPython to prevent the double
line spacing shown above, thanks.
--
Python is the second best programming language in the world.
But the best has yet to be invented. Christian Tismer
Mark Lawrence
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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