【发布时间】:2025-12-15 01:20:08
【问题描述】:
我想使用 vscode 和 jupyter 进行交互式 python 编程。除了单元格/块没有缩进或代码没有缩进时,一切都可以找到。以前,我尽可能使用 spyder。
我喜欢这种行为,因为当您有较长的类或函数定义(缩进)但只想从类/函数交互地运行几行时,它对于调试和开发很有用。
我已经尝试过官方的 python 扩展和 Don Jayamanne juypter 扩展。没有一个允许期望的行为。
更新:我刚刚发现不同的 python 版本在这方面表现不同。使用 python 3.6.6 和 3.7.2 缩进会引发错误,而使用 python 3.6.7 或 3.6.8 会忽略缩进并执行单元格。是否有解释为什么不同版本的行为不同或明确设置来处理这个问题?
#%%
print('This works')
#%%
print('This does not work, as it raises an indent error')
print('Update: This works in python version 3.6.7 or 3.6.8')
#%%
print('This does not work, as it is not recognized as a cell/block')
【问题讨论】:
标签: python visual-studio-code ipython jupyter