3

I am trying to add help text to function in my python script, similar to when parentheses are opened for input() or print(). Docstrings do something similar, but isn't useful when writing the code.

See below picture for what I want. The yellow pop up text for print is something I also want to turn up for the pythagorus() function, or something similar.

I also hope to apply this to functions other than this.

2
  • 1
    First of all, pythagorus() is a function, not a module. After that, this popup shows you available arguments of functions, not the docstring. Try creating a function with some arguments to see if they'll appear in this popup. Commented Feb 24, 2015 at 17:56
  • 1
    BTW, it's spelled Pythagoras, ending -as, not -us. Commented Feb 24, 2015 at 18:13

1 Answer 1

2

Looks like you're using idle. The yellow popup you see actually is the first line of the docstring of print. Usually idle displays the method signature (except for builtins like print) and the fist line of the docstring, so if you want to show up something helpful there, then use helpful docstrings.

In python3 you can also use function annotations to hint the correct usage of your function.

Your sample function would actually make more sense if it would take two arguments and return a value. Then it could look something like this:

def pythagorus(a: int, b: int) -> int:
    """ calculate a**2 + b**2

    ... usage example, etc ...
    """
    return math.sqrt(a**2 + b**2)

Which would show up in idle like this:

example_of_idle_display

Sign up to request clarification or add additional context in comments.

1 Comment

While this works in the shell, I was wondering is it would be possible to have this happen in the text editor. Is it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.