Python preprosessor

Tuomas Vesterinen tuomas.vesterinen at
Mon Jun 8 14:11:58 CEST 2009

Roger Binns wrote:
> Hash: SHA1
> Tuomas Vesterinen wrote:
>> I am intensively using So I have 2 codebase: one in py2 and the
>> other in py3.
> The expectation would be that you only maintain the py2 code and
> automatically generate the py3 code on demand using 2to3.
> It is possible to have the same code run under both versions, but not
> recommended.  As an example I do this for the APSW test suite, mostly
> because the test code deliberately explores various corner cases that
> 2to3 could not convert (nor should it try!).  Here is how I do the whole
> Unicode thing:
> if py3: # defined earlier
>   UPREFIX=""
> else:
>   UPREFIX="u"
> def u(x): # use with raw strings
>   return eval(UPREFIX+"'''"+x+"'''")
> # Example of use
> u(r"\N${BLACK STAR}\u234")
> You can pull similar stunts for bytes (I use buffers in py2), long ints
> (needing L suffix in some py2 versions), the next() builtin from py3,
> exec syntax differences etc.  You can see more details in the first 120
> lines of
> Roger
> Version: GnuPG v1.4.9 (GNU/Linux)
> iEYEARECAAYFAkosTxEACgkQmOOfHg372QS4rQCgl1ymNME2kdHTBUoc7/f2e+W6
> cbMAmwf7mArr7hVA8k/US53JE59ChnIt
> =pQ92

You have interesting solutions.


More information about the Python-list mailing list