Last active
October 18, 2024 01:08
-
-
Save disouzam/5e9ae770bf4bac194431661dd42adeca to your computer and use it in GitHub Desktop.
Python snippets for VS Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// 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" | |
// } | |
"Check Importable Modules": { | |
"prefix": "importablemodules", | |
"body": [ | |
"import pkgutil", | |
"", | |
"search_path = ['.'] # set to None to see all modules importable from sys.path", | |
"all_modules = [x[1] for x in pkgutil.iter_modules(path=search_path)]", | |
"print(\"Available modules to import: \")", | |
"nmodules=0", | |
"if len(all_modules) == 0:", | |
" print(all_modules)", | |
"for module in all_modules:", | |
" nmodules+=1", | |
" print(f\"{nmodules}: Module name: {module}\")" | |
], | |
"description": "Check the modules that can be imported at a given time" | |
}, | |
"List paths appended to sys.path": { | |
"prefix": "syspath", | |
"body": [ | |
"import sys", | |
"", | |
"print(\"Paths in sys.path:\")", | |
"npaths=0", | |
"for pathitem in sys.path:", | |
" npaths+=1", | |
" print(f\"{npaths}: Path: {pathitem}\")" | |
], | |
"description": "Print the paths that are appended to sys.path" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gists created following instructions here:
https://code.visualstudio.com/docs/editor/userdefinedsnippets