Skip to content

Instantly share code, notes, and snippets.

@ehatton
Last active April 28, 2020 13:28
Show Gist options
  • Save ehatton/f176d5e9480ca936cc409ace7423f8c9 to your computer and use it in GitHub Desktop.
Save ehatton/f176d5e9480ca936cc409ace7423f8c9 to your computer and use it in GitHub Desktop.
Python snippets for VS Code
# Python snippets for VS Code
{
"class": {
"prefix": "cls",
"body": [
"class ${1:ClassName}:",
"\tdef __init__(self):",
"\t\tself.$2 = $2$0"
],
"description": "Code snippet for class without parameters"
},
"class with 1 parameter": {
"prefix": "cls1",
"body": [
"class ${1:ClassName}:",
"\tdef __init__(self, ${2:param1}):",
"\t\tself.$2 = $2",
],
"description": "Code snippet for class with 1 parameter"
},
"class with 2 parameters": {
"prefix": "cls2",
"body": [
"class ${1:ClassName}:",
"\tdef __init__(self, ${2:param1}, ${3:param2}$0):",
"\t\tself.$2 = $2",
"\t\tself.$3 = $3",
],
"description": "Code snippet for class with 2 parameters"
},
"class with 3 parameters": {
"prefix": "cls3",
"body": [
"class ${1:ClassName}:",
"\tdef __init__(self, ${2:param1}, ${3:param2}, ${4:param3}$0):",
"\t\tself.$2 = $2",
"\t\tself.$3 = $3",
"\t\tself.$4 = $4"
],
"description": "Code snippet for class with 3 parameters"
},
"subclass": {
"prefix": "subcls",
"body": [
"class ${1:ClassName}(${2:SuperClass}):",
"\tdef __init__(self, ${3:param}):",
"\t\tsuper().__init__($3)"
],
"description": "Code snippet for class inheriting from another class"
},
"dataclass": {
"prefix": "dcls",
"body": [
"@dataclass",
"class ${1:ClassName}:",
"\t${2:field}: ${3:type}"
],
"description": "Code snippet for dataclass with 1 field"
},
"decorator": {
"prefix": "deco",
"body": [
"def ${1:decorator_name}(func):",
"\[email protected](func)",
"\tdef wrapper(*args, **kwargs):",
"\t\t$2",
"\t\treturn func(*args, **kwargs)",
"\treturn wrapper"
],
"description": "Code snippet for decorator function template"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment