Python #ifdef
Carlos Nepomuceno
carlosnepomuceno at outlook.com
Tue May 28 18:50:35 EDT 2013
________________________________
> Date: Tue, 28 May 2013 18:25:59 -0400
> Subject: Re: Python #ifdef
> From: joel.goldstick at gmail.com
> To: breamoreboy at yahoo.co.uk
> CC: python-list at python.org
[...]
>
> 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
Thanks Joel! In this case I think it does because I would like to have the same short benchmarking script to be runnable by Python 2 and Python 3.
The only piece of code that doesn't run on Python 2 is a to_bytes() single call. So it's not a huge maintenance load. ;)
I didn't try to write 'portable' code to Python 3 yet. What's the catch?
More information about the Python-list
mailing list