簡體   English   中英

如何獲取內置模塊的源代碼?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM