[英]How to get the source code of built-in module?
模塊或功能的源代碼可以從檢查中獲得。
import inspect
print(inspect.getsource(moduleName.function))
如果模塊是內置模塊怎么辦?
import sys
print(inspect.getsource(sys))
TypeError: <module 'sys' (built-in)> is a built-in module .
那我在哪里可以買到呢?
sys
模塊是少數幾個未在Python本身中實現,而是在本機代碼中實現的模塊之一。 C源代碼位於/Python/sysmodule.c
。
其他大多數模塊都直接在Python中實現。 您可以在Python安裝的lib
目錄中或source中找到這些源代碼 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.