How can I see Python's __builtins__ source code?

ε祈祈猫儿з 提交于 2020-02-04 01:24:23

问题


Can I get python to print the source code for __builtins__ directly?

OR (more preferably):

What is the pathname of the source code for __builtins__?


I at least know the following things:

  • __builtins__ is a module, by typing type(__builtins__).

  • I have tried the best-answer-suggestions to a more general case of this SO question: "Finding the source code for built-in Python functions?". But no luck:

    • print inspect.getdoc(__builtins__) just gives me a description.

    • inspect.getfile(__builtins__) just gives me an error: TypeError: <module '__builtin__' (built-in)> is a built-in module

    • https://hg.python.org/cpython/file/c6880edaf6f3/# does not seem to contain an entry for __builtins__. I've tried "site:" search and browsed several of the directories but gave up after a few.


回答1:


The __builtin__ module is implemented in Python/bltinmodule.c, a rather unusual location for a rather unusual module.




回答2:


I can't try it right now, but python default ide is able to open core modules easily (I tried with math and some more)

https://docs.python.org/2/library/idle.html

On menus. Open module.



来源:https://stackoverflow.com/questions/40851872/how-can-i-see-pythons-builtins-source-code

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