Python preprosessor

Tuomas Vesterinen tuomas.vesterinen at
Mon Jun 8 14:10:35 CEST 2009

R. David Murray wrote:
> Tuomas Vesterinen <tuomas.vesterinen at> wrote:
>> I am developing a Python application as a Python2.x and Python3.0 
>> version. A common code base would make the work easier. So I thought to 
>> try a preprosessor. GNU cpp handles this kind of code correct:
>> <>
>> #ifdef python2
>> print u'foo', u'bar'
>> #endif
>> #ifdef python3
>> print('foo', 'bar')
>> #endif
>> <end code>
>> results:
>>  > cpp -E -Dpython2
>> ...
>> print u'foo', u'bar'
>> Any other suggestions?
> There's a Google Summer of Code project to create a 3to2 processor.
> That would let you maintain the code in 3.x, and have it automatically
> translated on demand so that it will run under 2.x (where x goes back
> to at least 5, I think, but I'm not sure).
> Of course, it isn't finished yet, so it won't do you any good right at
> the moment :(
> --
> R. David Murray       
>     IT Consulting    System Administration    Python Programming

I found also a ready made py3to2-tool (test/develop/integrate python 3.0 
code natively under robust, software-rich python 2.5 environment) at:
It seems so complicated that I don't dare to try before some more 
experienced people has commented it.


More information about the Python-list mailing list