Search code examples
pythonpython-3.xanacondaspyder

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


Solution

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