Do the triple-quoted (docstring) messages in Pytho

2019-07-23 07:43发布

问题:

I usually write scripts to calculate or process things for my own consumption. Now I'm trying to write scripts for others.

I use both IDLE and a terminal, but I like just like the IDLE interface and find it more helpful. Today I "discovered" that I can add triple-quoted text under class and def and see them in real time when using IDLE, and I realize I can use those to help others know how to use these classes and methods.

But if run from a terminal this is all lost.

Question: Is it only IDLE users who are seeing these cues while they are typing a line that uses the class or method, or is this something that people using terminal could see while typing if they wanted to? I know that one could type A.__doc__ to see it for example, but the pop-up window is really convenient and helpful.

class A(object):
    """hey A!"""

    def __init__(self, x):
        """hey __int__!"""

        self.x = x

    def sqrx(self):
        """hey sqrx!"""

        print self.x**2

(just to see what would happen if)

But if I do this from a terminal all these prompts disappear.

nothing.

回答1:

The "triple-quoted messages" are docstrings, and they appear in different contexts.

For example:

  • When hitting ctrl+q (or whatever key is bound to the "Quick Documentation" action) in PyCharm:

    There is also an option to display the quick documentation pop-up while typing.

  • When calling help on the function:

    >> help(foo)
    Help on function foo in module __main__:
    
    foo()
         foo's docstring
    


I can not tell you about other IDEs as I don't use them.