简体   繁体   English

打印所有Python内置子模块和内置模块的功能

[英]Printing all the Python built-in sub-modules and functions of a builtin module

I want to print all the available functions and sub-modules in a built-in module. 我想在内置模块中打印所有可用的功能和子模块。 For example: 例如:

dir(__import__("sys"))

It gives a list of classes and methods. 它提供了类和方法的列表。

['__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

but what i want is , I want to check all the available methods inside the class sys.stdin ie 但是我想要的是,我想检查sys.stdin类内的所有可用方法,即

sys.stdin constains the following functions like sys.stdin包含以下功能,例如

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

So how to print all the availbale methods of a sub-module class. 因此,如何打印子模块类的所有可用方法。
I'm curious on how to implement this. 我很好奇如何实现这一点。
Thanks. 谢谢。
EDIT: 编辑:

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

You could use the same method that you used for sys module. 您可以使用与sys模块相同的方法。 ie

>>> 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']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM