Skip to content

Instantly share code, notes, and snippets.

@hibetterheyj
Last active January 7, 2022 16:26
Show Gist options
  • Save hibetterheyj/f15bcfe331ea9fa2abf2d772d473d2c1 to your computer and use it in GitHub Desktop.
Save hibetterheyj/f15bcfe331ea9fa2abf2d772d473d2c1 to your computer and use it in GitHub Desktop.
[VS Code snippet] Create default python header (V2022)
{
// Place your snippets for python here. Each snippet is defined under a snippet name and has a prefix, body and
// description. 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": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
// Misc
// Creating snippets with quotation marks inside: https://stackoverflow.com/a/40317156/7961693
//
// 1. header
// https://stackoverflow.com/a/16221186/7961693
"HEADER": {
"prefix": "header",
"body": [
"#!/usr/bin/env python3",
"# -*-coding:utf-8 -*-",
"# =============================================================================",
"\"\"\"",
"@Author : Yujie He",
"@File : $TM_FILENAME",
"@Date created : $CURRENT_YEAR/$CURRENT_MONTH/$CURRENT_DATE",
"@Maintainer : Yujie He",
"@Email : yujie.he@epfl.ch",
"\"\"\"",
"# =============================================================================",
"\"\"\"",
"The module provides ...",
"\"\"\"",
"# =============================================================================",
"\"\"\"",
"TODO:",
"1. ",
"\"\"\"",
"# =============================================================================",
],
},
//
// 2. if main
// https://github.com/microsoft/vscode-python/issues/2242
"IF": {
"prefix": "if_main",
"body": [
"if __name__ == \"__main__\":",
" main()"
],
},
// 3. current path
"CURR_DIR_PATH": {
"prefix": "curr_dir_path",
"body": [
"curr_dir_path = os.path.dirname(os.path.abspath(__file__))",
],
},
// 4. header_old
// created: 2021/10/20
// ref: https://blog.csdn.net/u012949658/article/details/104681351
// ref: https://gist.github.com/prandelicious/88941b81f23a26c6000b41a03f300c64
"HEADER_OLD": {
"prefix": "header_old",
"body": [
"# -*-coding:utf-8 -*-",
"\"\"\"",
"@File : $TM_FILENAME",
"@Time : $CURRENT_YEAR/$CURRENT_MONTH/$CURRENT_DATE",
"@Author : Yujie He",
"@Version : 1.0",
"@Contact : yujie.he@epfl.ch",
"@State : ${5|Dev,Test,Prod|}",
"\"\"\"",
"$0"
],
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment