2013-09-05 3 views

답변

3

당신은 __doc__를 사용할 수 있습니다

class Test(): 
    def test_method(self): 
     """I'm a docstring""" 
     print "test method" 


print Test.test_method.__doc__ # prints "I'm a docstring" 

또는 getdoc()inspect 모듈에서 :

inspect.getdoc(object)

가 cleandoc으로 정리 객체, ()에 대한 문서 문자열을 가져옵니다.

print inspect.getdoc(Test.test_method) # prints "I'm a docstring" 
1

현재 help()를 사용할 수 있습니다

>>> class Test: 
...  def foo(self, bar): 
...    """ Returns the parameter passed """ 
...    return bar 
... 
>>> help(Test.foo) 

결과 :

Help on method foo in module __main__: 

foo(self, bar) unbound __main__.Test method 
    Returns the parameter passed 
(END) 
관련 문제