VSCode Python代码提示自用


VSCode设置

文件 -> 首选项 -> 用户代码片段 -> 新建全局代码片段文件

码片段文件

{
	// Place your 全局 snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 
	// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 
	// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is 
	// used to trigger the snippet and the body will be expanded and inserted. Possible variables are: 
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. 
	// Placeholders with the same ids are connected.
	// Example:
	// "Print to console": {
	// 	"scope": "javascript,typescript",
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
    // }
    "class init": {
		"scope": "python",
		"prefix": "class $1 $2",
		"body": [
            "class $1(object):",
            "    def __init__(self$2):",
            "        self."
		],
		"description": "auto class init"
    },
    "class pass":{
        "scope": "python",
		"prefix": "classpass $1",
		"body": [
            "class $1: pass"
		],
		"description": "auto class pass"
    },
    "def pass":{
        "scope": "python",
		"prefix": "defpass $1",
		"body": [
            "def $1(): pass"
		],
		"description": "auto def pass"
    },
    "get path":{
        "scope": "python",
		"prefix": "import os",
		"body": [
            "import os",
            "",
            "def getScriptPath():",
            "    return os.path.split(os.path.realpath(__file__))[0]",
            ""
		],
		"description": "auto getScriptPath"
    },
    "env init":{
        "scope": "python",
		"prefix": "import sys",
		"body": [
            "#!/usr/bin/env python",
            "# coding:utf-8",
            "",
            "import sys",
            "reload(sys)",
            "sys.setdefaultencoding('utf-8')",
            ""
		],
		"description": "auto set utf8"
    },
    "logging":{
        "scope": "python",
		"prefix": "import logging $1",
		"body": [
            "import logging",
            "",
            "logger = logging.getLogger(__name__)",
            "logger.setLevel(level=logging.INFO)",
            "handler = logging.FileHandler('$1')",
            "handler.setLevel(level=logging.INFO)",
            "formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')",
            "handler.setFormatter(formatter)",
            "logger.addHandler(handler)",
            ""
		],
		"description": "auto logging"
    },
    "args":{
        "scope": "python",
		"prefix": "*a",
		"body": [
            "*args, **kwargs"
		],
		"description": "auto *args"
    },
    "closure":{
        "scope": "python",
		"prefix": "proxy $1 $2 $3",
		"body": [
            "def $1(func):",
            "    def proxy(*args, **kwargs):",
            "        $2",
            "        result = func(*args, **kwargs)",
            "        $3",
            "        return result",
            "    return proxy",
            ""
		],
		"description": "auto closure"
    }
}
发布了31 篇原创文章 · 获赞 11 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/MrRight17/article/details/103939119
今日推荐