1

I am a beginner with the Python. I am trying to run the following code to replace some labels in .txt annotation files.

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

but I am getting the following error:

File "<tokenize>", line 7
    if word="6":
    ^
IndentationError: unindent does not match any outer indentation level

I tried to find the indentation error but it looked alright to me. Plz help. tnx!

Max
  • 509
  • 1
  • 7
  • 21
  • 2
    You've got mixed tabs and spaces. Find your editor's "convert tabs to spaces" button and hit it, set your indentation to spaces, and check for this if it comes up again. – user2357112 May 24 '20 at 03:11
  • tnx @ user2357112 supports Monica. it helped – Max May 24 '20 at 03:28

2 Answers2

1

You use wrong Syntex of If and elif condition
Try below code

        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
prince09
  • 118
  • 5
1

if/elif takes a statement that returns a boolean value.

== is one such operator that checks for equality and returns true/false.

What you have in your code is =, which is an assignment operator and it does not check for equality.

Replace all the if/elif statements like this:

if word == "6":
Harshal Parekh
  • 5,918
  • 4
  • 21
  • 43