Extending the code of Python - adding language features

一曲冷凌霜 提交于 2020-01-01 16:31:11

问题


I have been programming in python exclusively for 4 years and have never really looked under the hood at the C code in which python is written. I have recently been looking into a problem that would involve modifying python at that level.

The code seems pretty consistent, and thus relatively easily understood. However, it's complex enough that it wasn't making sense to me just by studying it how it all worked together. Granted, I didn't spend a lot of time or effort on that, for want of a better resource. I also looked over the documentation on the python site. However, it is oriented more toward extending the language through modules.

I was hoping to find some straightforward documentation on how the parser works at the C level and how to extend the core language directly (adding language features). The module-oriented documentation provides some great insight into the way types are built and objects are managed, but I am looking for more.

Is there any such documentation out there?


回答1:


This article may help you get started. It takes a lot of information from the excellent PEP 339 - Design of the CPython Compiler.




回答2:


http://docs.python.org/extending/index.html - Custom modules/extensions

http://docs.python.org/c-api/index.html - C API, under the hood




回答3:


There's not too much written lore on this topic. Your best bet is to just simply follow the guidelines in PEP 306



来源:https://stackoverflow.com/questions/3505029/extending-the-code-of-python-adding-language-features

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!