User Tools

Site Tools


Writing Python 2-3 compatible code

Currently only Python 2 (latest version 2.7.13, ported but not online yet) is available for OpenVMS

Python 3 is clearly the future, but is not available on OpenVMS at the moment

Unfortunately there are few incompatibilities between the 2 versions Fortunately a tool exist to convert Python 2 code to Python 3 (2to3), but the generated code runs only on Python3.

It may be wise to write directly code compatible to Python 3 that also runs in Python 2 and it is possible.

The 2 most famous tools that do this are six and python-futures which are both included in the Python for OpenVMS kit

Six provides simple utilities for wrapping over differences between Python 2 and Python 3. It is intended to support codebases that work on both Python 2 and 3 without modification. six consists of only one Python file, so it is painless to copy into a project.

python-future is the missing compatibility layer between Python 2 and Python 3. Itallows you to use a single, clean Python 3.x-compatible codebase to support both Python 2 and Python 3 with minimal overhead.

python-future includes futurize which turns Python 2 code in code which runs on both Py2 and Py3: and pasteurize which turns Python 3 code into code which runs on both Py2 and Py3:

In order to write compatible code on OpenVMS, you can use the following imports

$ python
Python 2.7.13 (default, Dec 18 2016, 18:07:01) [DECC] on OpenVMS
Type "help", "copyright", "credits" or "license" for more information.
>>> import future
>>> import builtins
>>> import past
>>> import six


A PDF version is here:

This notebook shows you idioms for writing future-proof code that is compatible with both versions of
Python: 2 and 3. It accompanies Ed Schofield’s talk at PyCon AU 2014, “Writing 2/3 compatible code”.
(The video is here:
python2and3.txt · Last modified: 2017/04/20 14:26 by gl