Spyder shortcut to insert docstrings?

Question:

When I want to document my classes and functions I of course write:

def function(foo):
    """
    lovely documentation 
    """
    return 

But of course I am lazy and typing “””””” then pressing the left arrow 3 times and enter is just too much for me.

Is there a hot key in Spyder that gives you “””|””” where | is where the insertion cursor is

Much in the same way that pressing a left bracket in spyder immediately gives you the the right bracket with the insertion cursor between them: ( | )

If there isn’t one, is it possible to make one?
Thanks

Asked By: boi_mann

||

Answers:

By default the opening quotes is not closed in spyder. To enable the closing quotes go to:

Tools>Preferences>Editor>Advanced Settings and check on Automatic insertion of closing quotes

enter image description here

Now when you enter the fourth quotation mark, you will have the quotations as you wanted it, three on the left and three on the right like this: “””|””” or ”’|”’

Answered By: Ama Aje My Fren

When you type in triple quotes after a function header, an icon will pop up that says Generate docstring. When this happens, hit Enter.

Following docstring template will be generated:

def function (foo):
    """
    

    Parameters
    ----------
    foo : TYPE
        DESCRIPTION.

    Returns
    -------
    None.

    """
    return
Answered By: Nirbhai Singh

I think you are talking about this feature:
enter image description here

The default hotkey is Ctrl+Alt+D

Answered By: Taha
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.