gpt4 book ai didi

python - 为什么会出现此 Python 缩进错误?

转载 作者:可可西里 更新时间:2023-11-01 09:57:29 25 4
gpt4 key购买 nike

我在 Python 中遇到缩进错误,我不知道为什么以及如何解决它。

我寻找我可能遗漏的特殊字符,但没有找到;

为什么会出现这个错误?

user = {'_id':username}

users.find_one(user)

enter image description here

结论:切勿将制表符与空格混用!

最佳答案

此类错误的最常见原因是混用制表符和空格

要修复它,请尝试将文件中的所有制表符转换为空格。

来自 PEP 8 -- Style Guide for Python Code :

Tabs or Spaces?

Never mix tabs and spaces.

The most popular way of indenting Python is with spaces only. The second-most popular way is with tabs only. Code indented with a mixture of tabs and spaces should be converted to using spaces exclusively. When invoking the Python command line interpreter with the -t option, it issues warnings about code that illegally mixes tabs and spaces. When using -tt these warnings become errors. These options are highly recommended!

For new projects, spaces-only are strongly recommended over tabs. Most editors have features that make this easy to do.

关于python - 为什么会出现此 Python 缩进错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13253759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com