Python preprosessor

R. David Murray rdmurray at
Mon Jun 8 01:16:21 EDT 2009

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

More information about the Python-list mailing list