I am using py_compile
to convert the python files(.py) to .pyc
files.
py_compile.compile(py_src_file, doraise=True)
The python scripts contains code which have syntax both for python version 2.7 and 3.8 version.
The py_compile
when using with python 3.8 version generates an error for corresponding 2.7 syntax. Is there a way to check the python version while compiling the code and compile corresponding instruction only.
For ex:
if python_version == 2.7:
# py_compile should see 2.7 code
else:
# py_compile should see 3.8 code
I got some help in this answer: How would you do the equivalent of preprocessor directives in Python?, but don't know how to exactly use in my case. Thanks for your help.