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


Groups > comp.lang.python > #46345

Re: Python #ifdef

References <BLU176-W12FAFEA3C7AFD687855E04D7970@phx.gbl> <ko3af7$ar9$1@ger.gmane.org>
Date 2013-05-28 18:25 -0400
Subject Re: Python #ifdef
From Joel Goldstick <joel.goldstick@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2330.1369779961.3114.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Tue, May 28, 2013 at 6:18 PM, Mark Lawrence <breamoreboy@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

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


Thread

Re: Python #ifdef Joel Goldstick <joel.goldstick@gmail.com> - 2013-05-28 18:25 -0400
  Supporting both 2.x and 3.x in one code base [was Re: Python #ifdef] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-29 00:57 +0000

csiph-web