1
파이썬에서 클래스의 인스턴스가없는 메소드에서 docstring에 어떻게 접근 할 수 있습니까?인스턴스가없는 메소드 docstring을 피한다.
파이썬에서 클래스의 인스턴스가없는 메소드에서 docstring에 어떻게 접근 할 수 있습니까?인스턴스가없는 메소드 docstring을 피한다.
당신은 __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"
현재 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)
을