如何在创建 vscode 片段时转义 python 块评论?

How to escape python block comments when creating vscode snippets?

我为 python 函数定义创建了一个 vscode 片段,我想知道这是否是唯一 and/or 推荐的转义 python 块注释的方法( """ """).

全局片段文件

{   
    "def ": {
            "scope": "python",
            "prefix": "def func",
            "body": [
                "def  ():
                \"\"\"\" \"\"\"\    "
            ],
            "description": "Python function"
    }
}

输出

def  ():  
""" """   

在正文的单独字符串中指定每一行:

您可以选择文档字符串分隔符的种类。

文档字符串应缩进 (\t) 和正文。

{   
  "def": {
    "scope": "python",
    "prefix": "def func",
    "body": [
      "def  ():",
      "\t${2|\"\"\",''',\",'|}  ",
      "\t[=10=]"
    ],
    "description": "Python function"
  }
}

我刚刚看到 vscode 有一个用于块注释的内置变量。 块注释后的代码也要缩进。


"def": {
        "scope": "python",
        "prefix": "def func",
        "body": [
            "def  ():",
            "\t$BLOCK_COMMENT_START  $BLOCK_COMMENT_END",
            "\t[=10=]"
        ],
        "description": "Python function"