【发布时间】:2021-03-27 02:52:08
【问题描述】:
我最近一直在将应用程序移植到python3并开始遇到错误:
Traceback (most recent call last):
File "------.py", line 22, in <module>
import utils
File ---------.py, line 226
if account_doc is not None and 'vendor' in account_doc :
^
TabError: inconsistent use of tabs and spaces in indentation
下面是代码:
def getVendorName(access_key):
if access_key is not None and access_key != '':
account = AccountModule.Account(access_key)
account_doc = account.account_doc
if account_doc is not None and 'vendor' in account_doc :
return account_doc['vendor']
print("[ALARM] utils.getVendorName, account not found")
我检查了几个单独的 IDE,间距始终正确,并且始终是一个选项卡 - 在某些 IDE(VSCode)上它显示错误,而在其他 IDE 上则没有(PyCharm)。我试过使用制表符,也只使用两个空格,都不起作用。
程序在 python 2.7 上运行,但在 python 3.9 上不运行,文件编码为 UTF-8。 请帮忙!谢谢
【问题讨论】:
-
您必须有一些行同时使用制表符和空格。尝试在普通编辑器中打开文件并搜索选项卡。
-
您实际上必须找到不一致之处。在 Stack Overflow 上它是不可见的。一些 IDE 和命令行工具可能有助于自动格式化。顺便说一句,约定说每个缩进级别有四个空格。
标签: python python-3.x python-2.7 compiler-errors