Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Library to parse Python 2 and 3

I'm looking for a library that allows parsing and modification of Python 3 source code. There is the built-in ast module, but that doesn't allow parsing Python 3 code from Python 2 and vice versa.

Is there such a library, or a way to make the ast module recognize Python 2 code on Python 3?

like image 553
phihag Avatar asked Aug 08 '26 22:08

phihag


1 Answers

Python's lib2to3 library includes a code parser can can parse both Python 2 and Python 3 code. It's not well documented though. This chapter from the porting book provides an introduction. If you want to modify code (refactoring, maybe) then 2to3 could very well be exactly what you are looking for.

like image 189
Lennart Regebro Avatar answered Aug 10 '26 12:08

Lennart Regebro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!