My dotfiles
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

25 行
1.2 KiB

  1. # Query Jupyter server for the value of a variable
  2. import json
  3. _VSCODE_max_len = 200
  4. # In IJupyterVariables.getValue this '_VSCode_JupyterTestValue' will be replaced with the json stringified value of the target variable
  5. # Indexes off of _VSCODE_targetVariable need to index types that are part of IJupyterVariable
  6. _VSCODE_targetVariable = json.loads('_VSCode_JupyterTestValue')
  7. _VSCODE_evalResult = eval(_VSCODE_targetVariable['name'])
  8. # Find shape and count if available
  9. if _VSCODE_targetVariable['type'] in ['ndarray','DataFrame','Series']:
  10. _VSCODE_targetVariable['shape'] = str(_VSCODE_evalResult.shape)
  11. if _VSCODE_targetVariable['type'] in ['tuple', 'str', 'dict', 'list', 'set', 'ndarray','DataFrame','Series']:
  12. _VSCODE_targetVariable['count'] = len(_VSCODE_evalResult)
  13. # Get the string of the eval result, truncate it as it could be far too long
  14. _VSCODE_targetValue = str(_VSCODE_evalResult)
  15. if len(_VSCODE_targetValue) > _VSCODE_max_len:
  16. _VSCODE_targetVariable['truncated'] = True
  17. _VSCODE_targetVariable['value'] = _VSCODE_targetValue[:_VSCODE_max_len]
  18. else:
  19. _VSCODE_targetVariable['value'] = _VSCODE_targetValue
  20. print(json.dumps(_VSCODE_targetVariable))