Python preprosessor

R. David Murray rdmurray at bitdance.com
Mon Jun 8 07:16:21 CEST 2009


Tuomas Vesterinen <tuomas.vesterinen at iki.fi> 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:
> 
> <test_cpp.py>
> #ifdef python2
> print u'foo', u'bar'
> #endif
> #ifdef python3
> print('foo', 'bar')
> #endif
> <end code>
> 
> results:
>  > cpp -E -Dpython2 test_cpp.py
> ...
> 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                 http://www.bitdance.com
    IT Consulting    System Administration    Python Programming




More information about the Python-list mailing list