Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between compiler and ast module in python

Tags:

python

The compiler module has been deprecated in python 2.6. Does anybody know what is the reason behind the deprecation ? Is the ast module a direct replacement ? Will the ast module be supported in python 3k ?

like image 609
Frankie Ribery Avatar asked Feb 20 '26 23:02

Frankie Ribery


2 Answers

The compiler module was a Python compiler written in Python. It was horribly slow and a pain to maintain.

The ast module is a smarter solution to the same problem: it provides Python level access to the actual compiler used when importing modules. Since it is just a visible API for the builtin compiler, it isn't going anywhere.

ast isn't a drop-in replacement for compiler (i.e. the APIs are different), but it certainly covers many of the same use cases.

like image 127
ncoghlan Avatar answered Feb 22 '26 14:02

ncoghlan


Yes, the ast module replaces the compiler module. And what do you mean by "will be supported"? Python 3 has been out for years, and of course ast is part of its standard library.

Reasons for the removal can be found here.

like image 40
Tim Pietzcker Avatar answered Feb 22 '26 13:02

Tim Pietzcker



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!