0

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?

1 Answer 1

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

I'd prefer to do it at runtime.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.