Как получить текст ошибки в python и немного про pylance в vscode
Теги:
Как получить текст ошибкки в python
try:
some_method()
except Exception as e:
s = str(e)
Using repr:
>>> try:
... print(x)
... except Exception as e:
... print(repr(e))
...
NameError("name 'x' is not defined")
Using str:
>>> try:
... print(x)
... except Exception as e:
... print(str(e))
...
name 'x' is not defined
Another way
try:
1/0
except Exception, e:
print e.message
try:
some_method()
except Exception as e:
if {value} in e.args:
{do something}
Проблема с пайленс в [vscode]
Unresolved import warnings
These extra roots must be specified to the language server. The easiest way to do this (with the VS Code Python extension) is to create a workspace configuration which sets python.analysis.extraPaths. For example, if a project uses a sources directory, then create a file .vscode/settings.json in the workspace with the contents:
{
"python.analysis.extraPaths": ["./sources"]
}
Смотри как получить сообщение ошибки в ви де строки тут: [2021-09-10-daily-note]