boi_mann
boi_mann

Reputation: 45

Spyder shortcut to insert docstrings?

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

Upvotes: 4

Views: 13030

Answers (3)

Taha
Taha

Reputation: 778

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

The default hotkey is Ctrl+Alt+D

Upvotes: 3

Nirbhai Singh
Nirbhai Singh

Reputation: 51

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

Upvotes: 4

Ama Aje My Fren
Ama Aje My Fren

Reputation: 266

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 '''|'''

Upvotes: 6

Related Questions