打印一个内置modu的所有Python内置子模块和函数

2024-10-01 02:28:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在一个内置模块中打印所有可用的函数和子模块。 例如:

dir(__import__("sys"))

它给出了类和方法的列表。你知道吗

['__displayhook__',
'__doc__',
'__egginsert',
'__excepthook__',
'__name__',
'__package__',
'__plen',
'__stderr__',
'__stdin__',
'__stdout__',
'argv',
'builtin_module_names',
'byteorder',
'call_tracing',
'stdin',
'stdout',
'subversion',
'version',
'version_info',
'warnoptions',
'winver'] ...etc

但是我想检查类中所有可用的方法标准输入

标准输入包含以下函数

sys.stdin.close  
sys.stdin.name       
sys.stdin.softspace  
sys.stdin.readline  
sys.stdin.readlines  
sys.stdin.seek  ...etc

那么如何打印一个子模块类的所有可用方法。
我很好奇如何实现这一点。
谢谢。
编辑:

module_name = "sys" #module is taken from the user
smod ="stdin" # select the desire sub-module
param = module_name + smod
def printFns(param):
     #code to print all the available functions

Tags: 模块the方法函数name标准paramversion
1条回答
网友
1楼 · 发布于 2024-10-01 02:28:03

您可以使用与sys模块相同的方法。 i、 e

>>> import sys
>>> dir(sys.stdin)
['__class__', '__delattr__', '__doc__', '__enter__', '__exit__', '__format__', '__getattribute__', '__hash__', '__in
educe__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'close', 'closed'
'flush', 'isatty', 'mode', 'name', 'newlines', 'next', 'read', 'readinto', 'readline', 'readlines', 'seek', 'softspa
'writelines', 'xreadlines']

相关问题 更多 >