Skip to main content
 首页 » 编程设计

python之列出标准的 Python 库模块和适当的子模块

2025年05月04日9txw1958

有希望有一种简单的方法来列出 Python 标准库模块和类子模块吗?

我读了this问题,但它对我不起作用,不是因为它列出了所有可用模块(我知道可以调整以避免),但它不包括子模块。例如,它列出了模块 urllib 但没有子模块类:

urllib.ContentTooShortError      urllib.main                      urllib.splituser 
urllib.FancyURLopener            urllib.noheaders                 urllib.splitvalue 
urllib.MAXFTPCACHE               urllib.os                        urllib.ssl 
urllib.URLopener                 urllib.pathname2url              urllib.string 
urllib.addbase                   urllib.proxy_bypass              urllib.sys 
urllib.addclosehook              urllib.proxy_bypass_environment  urllib.test 
urllib.addinfo                   urllib.quote                     urllib.test1 
urllib.addinfourl                urllib.quote_plus                urllib.thishost 
urllib.always_safe               urllib.reporthook                urllib.time 
urllib.basejoin                  urllib.socket                    urllib.toBytes 
urllib.c                         urllib.splitattr                 urllib.unquote 
urllib.ftpcache                  urllib.splithost                 urllib.unquote_plus 
urllib.ftperrors                 urllib.splitnport                urllib.unwrap 
urllib.ftpwrapper                urllib.splitpasswd               urllib.url2pathname 
urllib.getproxies                urllib.splitport                 urllib.urlcleanup 
urllib.getproxies_environment    urllib.splitquery                urllib.urlencode 
urllib.i                         urllib.splittag                  urllib.urlopen 
urllib.localhost                 urllib.splittype                 urllib.urlretrieve 

还有其他办法吗?

请您参考如下方法:

要深入了解子模块,请使用 inspect和 pyclbr模块。这些与 pydoc、help 和 sphinx 使用的支持工具相同。

祝你的工具提示制作者好运。