Nick Nick - 1 month ago 25
Python Question

How to debug indentation errors in python

I am trying to write my very first python script. This was working but then after some slight refactoring I have, apparently, broken the indentation. I can not determine what is the problem. The interpretor complains about the following method. Can someone point it out?

def dataReceived(self, data):
a = data.split(':')
print a
if len(a) > 1:
command = a[0]
content = a[1]

msg = ""
if command == "iam":
self.name = content
msg = self.name + " has joined"

elif command == "msg":
msg = self.name + ": " + content
print msg



The error reads: File "python_server.py", line 17
a = data.split(':')
^ IndentationError: expected an indented block

Answer

You start using a text editor that allows you to show indents, and you become consistent about using spaces instead of tabs, and you enforce that in your editor.