2014-09-30 5 views
0

내장 모듈에 사용 가능한 모든 기능과 서브 모듈을 인쇄하고 싶습니다. 예 :내장 된 모듈의 모든 파이썬 내장 서브 모듈과 기능을 인쇄하십시오.

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 
처럼 다음과 같은 기능 즉

sys.stdin constains sys.stdin 클래스 내부의 모든 가능한 방법을 확인하려면

서브 모듈 클래스의 모든 availbale 메소드를 출력하는 방법.
이 방법을 구현하는 방법에 대해 궁금합니다.
감사합니다.
편집 :

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 
+0

시도가 각 반복 및 유형 –

답변

0

당신은 당신이 sys 모듈에 사용 된 것과 같은 방법을 사용할 수 있습니다. 즉

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

를 가져온 다음으로 hasattr (항목, '__call__')와 isinstance (항목, types.FunctionType)와 함께 테스트 할 문자열로 전달할 수 있습니다 난 할 수 있도록 모든 하위 모듈을 반복하고 해당 기능을 인쇄합니까? – dragfire

+0

수정 사항을 추가했습니다. 나는 사용자로부터 모듈 이름을 가져 와서 그것을 인쇄하고 싶다. – dragfire

관련 문제