How to print Docstring of python function from inside the function itself?

后端 未结 8 1647
無奈伤痛
無奈伤痛 2020-12-04 23:26

I want to print the docstring of a python function from inside the function itself. for eg.

def my_function(self):
  \"\"\"Doc string for my function.\"\"\"
         


        
8条回答
  •  猫巷女王i
    2020-12-05 00:06

    Try:

    class MyClass():
        # ...
        def my_function(self):
            """Docstring for my function"""
            print MyClass.my_function.__doc__
            # ...
    

    (*) There was a colon (:) missing after my_function()

提交回复
热议问题