Home > Back-end >  About adding a snippet for python in vs code
About adding a snippet for python in vs code

Time:05-07

How to write a snippet for 'main' function in vs code? It's not allowing to put double "" in between the body. Here is what I have written:

"Print to console": {
        "prefix": "mai",
        "body": [
            "if __name__ == __main__:"
            
        ],
        "description": "This throws main"

And I want this:

if __name__ == '__main__':
   pass

How to make this snippet?

CodePudding user response:

Try this one.

"Print to console": {
        "prefix": "mai",
        "body": [
            "if __name__ == '__main__':",
            "\tpass"
        ],
        "description": "Whatever you want to write."
    }

CodePudding user response:

Paste into https://snippet-generator.app/ that formats it into the necessary json. You copy that (there’s a button) and then you just paste it into your snippet file.

  • Related