[Python-il] Where should Python 2/Py3 compatibility shims be placed?

Shlomi Fish shlomif at shlomifish.org
Sat Apr 8 21:22:27 IDT 2017

Hi all!

I sometimes put (per a hint I found on a web search) code like that at the
beginning of my Python programs:

if sys.version_info > (3,):
    long = int
    xrange = range


This is a py2/py3 compatibility shim.

My question is whether I should put it only at the main program's file or also
at each and every *.py module that I load? I'm not sure I understand the python
handling of symbols well enough to answer that.

Thanks and happy holidays!

	Shlomi Fish

More information about the Python-il mailing list