Monday, September 6, 2010

IndentationError: unindent does not match any outer indentation level


I got this err:
File "ru16.py", line 23
self.relay = Serial(port = port)
^
IndentationError: unindent does not match any outer indentation level

after I edited my python codes as following:

def __init__(self, port = '/dev/ttyUSB0', bps = 9600, timeout = 0.1):
"""Open serial port, set baud rate, timeout,
switch all relays off immediately"""
self.relay = Serial(port = port)
self.relay.xonxoff = False
self.relay.rtscts = False
self.relay.baudrate = bps
self.relay.timeout = timeout
self.relay.open()
self.allOff()

Later I found that it's because I've somehow mixed up tabs and spaces in my gedit editor. So if you met with this same err as mine. There might be spaces mixed in with your tabs. Try doing a search&replace to replace all tabs with a few spaces.

You could use:

python -m tabnanny yourfile.py

to check or instead you just set up your editor correctly.

No comments:

Post a Comment