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?
asked Jan 19, 2017 at 1:42
Superbest
26.8k16 gold badges73 silver badges140 bronze badges
1 Answer 1
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.
Sign up to request clarification or add additional context in comments.
1 Comment
Superbest
I'd prefer to do it at runtime.
Explore related questions
See similar questions with these tags.
lang-py