How to determine if a python module is python 2 or python 3?

Python 2 and Python 3 are subtle differences, which mean that it is impossible to look at the python module, and, of course, know, just because of the automatic analysis of the code, if it will work the same in python 2 and python 3. (Right? It seems the answer is possible whether to check whether python source code was written for only one version (python 2 or python 3) )

Therefore, I suppose there must be some convention by which the developer can annotate the file in order to explicitly indicate that it is intended to be compatible with Python 2, Python 3, or both, so that this annotation can be read by the developers, it is automatically checked and etc.

What is this agreement?

I do not see different file extensions, for example .py2 vs .py3. I do not see the declaration of a global variable intended to work as metadata. But something seems to exist, besides special comments in the code and readme files. So what is it?

+6
source share
1 answer

Unfortunately, in fact there is no official way to indicate it. However, a common way is to specify the required version of Python in distribution metadata.

setup.py ( setup.cfg setuptools), python_requires option PEP440. . PEP 345 - Python, Requires-Python . / Python.

README . PyPI / github.

+6

All Articles