Ai
1 Star 0 Fork 0

joyni/vscode-python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
getJupyterVariableShape.py 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
# Query Jupyter server for defined variables list
# Tested on 2.7 and 3.6
import json as _VSCODE_json
# In IJupyterVariables.getValue this '_VSCode_JupyterTestValue' will be replaced with the json stringified value of the target variable
# Indexes off of _VSCODE_targetVariable need to index types that are part of IJupyterVariable
_VSCODE_targetVariable = _VSCODE_json.loads("""_VSCode_JupyterTestValue""")
_VSCODE_evalResult = eval(_VSCODE_targetVariable["name"])
# Find shape and count if available
if hasattr(_VSCODE_evalResult, "shape"):
try:
# Get a bit more restrictive with exactly what we want to count as a shape, since anything can define it
if isinstance(_VSCODE_evalResult.shape, tuple):
_VSCODE_shapeStr = str(_VSCODE_evalResult.shape)
if (
len(_VSCODE_shapeStr) >= 3
and _VSCODE_shapeStr[0] == "("
and _VSCODE_shapeStr[-1] == ")"
and "," in _VSCODE_shapeStr
):
_VSCODE_targetVariable["shape"] = _VSCODE_shapeStr
del _VSCODE_shapeStr
except TypeError:
pass
if hasattr(_VSCODE_evalResult, "__len__"):
try:
_VSCODE_targetVariable["count"] = len(_VSCODE_evalResult)
except TypeError:
pass
print(_VSCODE_json.dumps(_VSCODE_targetVariable))
del _VSCODE_json
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/luluunusually/vscode-python.git
git@gitee.com:luluunusually/vscode-python.git
luluunusually
vscode-python
vscode-python
master

搜索帮助