Superbest
Superbest

Reputation: 26602

How to validate syntax of Python2 code from Python3?

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?

Upvotes: 0

Views: 474

Answers (1)

Coding Pig
Coding Pig

Reputation: 66

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.

Upvotes: 1

Related Questions