Skip to content

Instantly share code, notes, and snippets.

@rcdevgames
Forked from kpalin/python.json
Created June 6, 2022 14:39
Show Gist options
  • Save rcdevgames/28f5e62f4fdb062bd161d38a50061554 to your computer and use it in GitHub Desktop.
Save rcdevgames/28f5e62f4fdb062bd161d38a50061554 to your computer and use it in GitHub Desktop.
vs code snippet pyscript for python boilerplate
{
// 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"
// }
"Python script start": {
"scope": "python",
"prefix": "pyscript",
"body":[
"#!/usr/bin/env python",
"#-*- coding: utf-8 -*-",
"'''$1 ",
"",
"Created at $CURRENT_DAY_NAME $CURRENT_DATE $CURRENT_MONTH_NAME $CURRENT_YEAR $CURRENT_HOUR:$CURRENT_MINUTE by Kimmo Palin <kpalin@helsinki.fi>",
"'''",
"",
"__version__ = \"0.1\"",
"",
"from argparse import Namespace",
"from os import EX_OK",
"import sys",
"from typing import List, Optional",
"",
"def parse_args(args: List[str]) -> Namespace:",
" import argparse",
" description = \"\\n\".join(__doc__.splitlines()[:-1]).strip()",
"",
" parser = argparse.ArgumentParser(description=description)",
" ",
" parser.add_argument('-i', '--input',",
" help='Input file [default:%(default)s]',",
" default='/dev/stdin')",
" ",
" version = f\"%(prog)s {__version__}\"",
" parser.add_argument(\"--version\", action=\"version\", version=version)",
"",
" parser.add_argument('-V', '--verbose',default=False,action='store_true',",
" help='Be more verbose with output' )",
"",
" args = parser.parse_args()",
"",
" import logging",
" if args.verbose:",
" logging.basicConfig(level=logging.INFO,",
" format='%(asctime)s:%(funcName)s:%(levelname)s:%(message)s')",
"",
" return args",
"",
"",
"def main(argv: List[str] = sys.argv[1:]) -> int:",
" args = parse_args(argv)",
" $0",
"",
" return EX_OK",
"",
"if __name__ == '__main__':",
" sys.exit(main())"
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment