复制步骤:
将以下内容放入keybindings.json文件:
// Place your key bindings in this file to override the defaults
[
{ "key": "shift+enter",
"command": "jupyter.execSelectionInteractive",
"when": "editorTextFocus && jupyter.ownsSelection && !findInputFocussed && !notebookEditorFocused && !replaceInputFocussed && editorLangId == 'python'"
},
{
"key": "ctrl+shift+enter",
"command": "python.execSelectionInTerminal",
"when": "editorTextFocus && !findInputFocussed && !jupyter.ownsSelection && !replaceInputFocussed && editorLangId == 'python'"
},
]
制造测试.py:
#%%
# move working directory to the script
import os
mydir = os.path.dirname(os.path.abspath(__file__))
os.chdir(mydir)
选择第1-5行并按shift+enter
预期结果(将打开一个交互式窗口并运行脚本):
# move working directory to the script...
打印出当前目录
观察结果(在终端中得到以下误差):
>>> mydir
Traceback (most recent call last):
File "", line 1, in
NameError: name 'mydir' is not defined