How to define a bytes literal in Python 2.x for porting to Python 3.x using 2to3?

Martin v. Loewis martin at v.loewis.de
Sat Jan 1 17:57:10 EST 2011


> 1. Code running in multiple versions has to be syntactically correct in
> every detail all versions in order to be compiled without error.
> However, version specific syntax *can* be used in modules that are
> conditionally imported and therefore conditionally compiled and executed.

I also encourage people to use 2to3. Then this requirement (must be
syntactically correct in all Python versions) goes away: it is ok to
write source that doesn't compile on Python 3, and still *run* it
on Python 3.

OTOH, writing code that only supports newer 2.x versions isn't helped
by 2to3, so compatibility within 2.x is more important to consider than
compatibility between 2.x and 3.x.

Regards,
Martin



More information about the Python-list mailing list