【发布时间】:2020-05-24 03:08:50
【问题描述】:
我是 Python 的初学者。我正在尝试运行以下代码来替换 .txt 注释文件中的一些标签。
import os
for txt_in in os.listdir(r"uncorrected-YOLO_darknet"):
with open(txt_in) as infile:
for line in infile:
word=line.split(" ")[0]
if word="6":
word.replace('6', '5')
elif word="9":
word.replace('9', '6')
elif word="10":
word.replace('10', '7')
elif word="11":
word.replace('11', '8')
else:
continue
break
但我收到以下错误:
File "<tokenize>", line 7
if word="6":
^
IndentationError: unindent does not match any outer indentation level
我试图找到缩进错误,但对我来说看起来没问题。请帮忙。 tnx!
【问题讨论】:
-
你有混合制表符和空格。找到编辑器的“将制表符转换为空格”按钮并点击它,将缩进设置为空格,并检查是否再次出现。
-
tnx @ user2357112 支持莫妮卡。它有帮助
标签: python error-handling