I am in Python3. I have a bunch of Python2 .py files. For each of these files, I need to check whether the contents are valid Python2 code and return it as a boolean. The files are small scripts, sometimes they may import things or have a function or class, but mostly they are pretty simple.
How can I do this?
Do you do it at build time? If so, you can try run 2to3 and parse its output to determine if the file is valid Python 2 code.
How to validate syntax of Python2 code from Python3?