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 constains the following functions like
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. 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']
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.