如何确定哪些 Python 标准库模块包含某个方法? [英] How to determine which Python standard library module(s) contain a certain method?

查看:60
本文介绍了如何确定哪些 Python 标准库模块包含某个方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个方法名,如何确定标准库中的哪些模块包含该方法?

Given a method name, how to determine which module(s) in the standard library contain this method?

例如如果有人告诉我一个名为 strip() 的方法,但没有告诉我它是如何工作的或者它是 str 的一部分,我将如何去找出哪个模块它属于?我无意中的意思是使用 Python 本身来查找,而不是谷歌搜索Python strip":)

E.g. If I am told about a method called strip(), but told nothing about how it works or that it is part of str, how would I go and find out which module it belongs to? I obliviously mean using Python itself to find out, not Googling "Python strip" :)

推荐答案

问题是,strip 没有在任何模块中定义.它根本不是标准库的一部分,而是 str 上的一个方法,而后者又是一个内置类.所以实际上没有任何方法可以遍历模块来找到它.

The trouble is, strip is not defined in any module. It is not a part of the standard library at all, but a method on str, which in turn is a built in class. So there isn't really any way of iterating through modules to find it.

这篇关于如何确定哪些 Python 标准库模块包含某个方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆