VSCode设置
文件 -> 首选项 -> 用户代码片段 -> 新建全局代码片段文件
码片段文件
{
"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"
}
}