Python #ifdef

Joel Goldstick joel.goldstick at gmail.com
Tue May 28 18:25:59 EDT 2013


On Tue, May 28, 2013 at 6:18 PM, Mark Lawrence <breamoreboy at yahoo.co.uk>wrote:

> On 28/05/2013 20:46, Carlos Nepomuceno wrote:
>
>> Are there Python 'preprocessor directives'?
>>
>> I'd like to have something like '#ifdef' to mix code from Python 2 and 3
>> in a single file.
>>
>> Is that possible? How?
>>
>>
> https://pypi.python.org/pypi/**six/1.3.0<https://pypi.python.org/pypi/six/1.3.0>
>
> --
> If you're using GoogleCrap™ please read this http://wiki.python.org/moin/*
> *GoogleGroupsPython <http://wiki.python.org/moin/GoogleGroupsPython>.
>
> Mark Lawrence
>
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>

my original response was from cell phone.  I just answered that you can't
do ifdefs, implying that there is no preprocessor in python.  I learned a
lot of things I didn't know reading the thread, but I wonder if it is a
good idea in general to try to write code like this.  -- combined 2.x/3.x
codebase can be a bear to maintain.  I wouldn't do it unless there was some
imposing reason that I must.  Its not just print() -- that isn't bad, but
changes in module names (urllib), arithmetic, and unicode especially make
this idea in general, very tricky.  Pity the next developer who needs to
try to maintain it.

So, maybe you CAN do it, but SHOULD you want to do it?

-- 
Joel Goldstick
http://joelgoldstick.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130528/de4d2067/attachment.html>


More information about the Python-list mailing list