python - 使用 Python 在 Visual Studio Code 中意外缩进

标签 python visual-studio-code indentation

以下代码

accounts = f.get_sepa_accounts()

for account in accounts:
    print(account)

抛出以下错误:

print(account)   File "<stdin>", line 1
print(account)
^ IndentationError: unexpected indent




我刚搬到 Visual Studio Code,所以不知道这是否是应用程序特有的问题。我已经尝试了 4 个空格和一个制表符......什么也没做。

谢谢!

最佳答案

您可能在缩进时使用了制表符。您可以通过选择代码来检查这一点。选中后,选项卡会在 VS 代码中用向右的箭头突出显示,如下图所示:-
enter image description here
注意第二行中的两个箭头。看看第二行是如何因此出错的。
您可以通过选择两个选项卡并按 ctrl +h 来解决此问题。替换为适量的空格。
简而言之,用空格替换制表符。

关于python - 使用 Python 在 Visual Studio Code 中意外缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52224313/

相关文章:

python - 如何确定Python整数形式的表达式的值?

typescript - VS代码: How to enable links in a webpage in the Webview

javascript - 为什么我的 Intellisense 消失在 Visual Studio 中的 Javascript 文件中?

objective-c - UITableViewCell 的图像没有缩进

类似 c 语言的 Emacs 模式

python - 在 Python 中跨列应用多个函数(均值、STD 等)

python - 如何获得乘以零得到零的浮点无穷大

python - 使用 sklearn 的 KFold 分离 Pandas 数据框

visual-studio-code - VSCode 错误装饰默认为文本不透明度(而不是波浪下划线)

f# - 无法在 VS 代码上使用 FSI