Get the latest tech news

Python’s Preprocessor


Every now and then you hear outrageous claims such as “Python has no preprocessor”.

If your language extension transforms syntactically valid Python, it is possible to use the ast module to parse the source file, modify the resulting abstract syntax tree and finally unparse it. Custom codecs in conjunction with path configuration files can drastically change the behavior of the Python interpreter. If you want to play around with your own preprocessors but do not wish to mess with site-packages directly, introduce path configuration files and write all the boilerplate yourself, you can instead use magic_codec.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of python

python

Photo of Preprocessor

Preprocessor

Photo of Pydong

Pydong

Related news:

News photo

Taichi: Productive, portable, and performant GPU programming in Python

News photo

PyScript: An open source platform for Python in the browser

News photo

Approximating sum types in Python with Pydantic