1

I am getting an indentation error and I cant see why, I defined two lists of dicts, the first one is fine, but the second one (which follows the same format) is throwing an indentation error.

list one (no problems):

itemData = [{'id': 11, 'model': 'm1', 'serial': 'ser123', 'location': 3, 'distance': 2, 'loc': 3},
            {'id': 12, 'model': 'm1', 'serial': 'ser456', 'location': 3, 'distance': 2, 'loc': 3}]

first version of list two:

itemData2 = [{'id': 11, 'model': 'm1', 'serial': 'ser123', 'location': 3, 'distance': 2, 'loc': 3},
             {'id': 12, 'model': 'm1', 'serial': 'ser456', 'location': 3, 'distance': 2, 'loc': 3},
             {'id': 13, 'model': 'm2', 'serial': 'ser678', 'location': 5, 'distance': 2, 'loc': 5}]

throws:

Traceback (most recent call last):
  File "job_manager.py", line 1, in <module>
    from NewJM import JobMonitor
  File "C:\Users\Jonathan\Documents\Coding\Python\Logistics Code\NewJM.py", line 56
itemData2 = [{'id': 11, 'model': 'm1', 'serial': 'ser123', 'location': 3, 'distance': 2, 'loc': 3},
                                                                                                  ^
IndentationError: unindent does not match any outer indentation level

second version of list two:

itemData2 = [
    {'id': 11, 'model': 'm1', 'serial': 'ser123', 'location': 3, 'distance': 2, 'loc': 3},
    {'id': 12, 'model': 'm1', 'serial': 'ser456', 'location': 3, 'distance': 2, 'loc': 3},
    {'id': 13, 'model': 'm2', 'serial': 'ser678', 'location': 5, 'distance': 2, 'loc': 5}
]

throws:

Traceback (most recent call last):
  File "job_manager.py", line 1, in <module>
    from NewJM import JobMonitor
  File "C:\Users\Jonathan\Documents\Coding\Python\Logistics Code\NewJM.py", line 56
itemData2 = [
            ^
IndentationError: unindent does not match any outer indentation level

I am confused as to why this is happening, especially since the first version of list two is a direct copy of list one only with the addition of another dict. Any ideas?

VPfB
  • 14,927
  • 6
  • 41
  • 75
ThriceGood
  • 1,633
  • 3
  • 25
  • 43
  • 4
    Please post enough code for us to reproduce the issue. In the meantime, make sure you're not mixing tabs and spaces. – code_dredd Nov 06 '15 at 12:05
  • This looks like an error where `itemData2` is on a line that dedented relative to a previous line, but without matching a prior level of indentation. Check above the error location, make sure your indentation is lined up with some code above you. Also, make sure your editor is using solely spaces, no tabs, and a consistent four space indent per PEP 8; it's not just for style, in a whitespace sensitive language you need to use a standard form or you can get subtle errors. – ShadowRanger Nov 06 '15 at 12:06

3 Answers3

1

It's look like you have tabs with spaces mix in your code. Symple copy-paste of your code from your question works correctly.

Penguinolog
  • 234
  • 1
  • 6
  • it was kind of strange, when pasting the code in from sublime text, it appeared with the wrong (erronous) indentation, but this indentation does not actually appear in sublime text, as in, what it looks like in my question is what it looked like in sublime text, only the indentation error was occurring none the less. anyways its fixed now! – ThriceGood Nov 06 '15 at 14:46
0

It looks like the indentation is occurring on that line, I'd add some whitespace checking and adding pyflakes as an extra precaution. In the meantime, I'd check to make sure the indentation isn't happening before or after that line.

hematag
  • 7
  • 4
0

reading this post:

IndentationError: unindent does not match any outer indentation level

(and the above comments)

led me to investigating the whitespace surrounding the itemData2 list,

using a ctrl + / command to comment the list out i found this:

    #   itemData2 = [
    #     {'id': 11, 'model': 'm1', 'serial': 'ser123', 'location': 3, 'distance': 2, 'loc': 3},
          # {'id': 12, 'model': 'm1', 'serial': 'ser456', 'location': 3, 'distance': 2, 'loc': 3},
    #     {'id': 13, 'model': 'm2', 'serial': 'ser678', 'location': 5, 'distance': 2, 'loc': 5}
 #   ]

when it should have been like this:

    # itemData2 = [
    #   {'id': 11, 'model': 'm1', 'serial': 'ser123', 'location': 3, 'distance': 2, 'loc': 3},
    #   {'id': 12, 'model': 'm1', 'serial': 'ser456', 'location': 3, 'distance': 2, 'loc': 3},
    #   {'id': 13, 'model': 'm2', 'serial': 'ser678', 'location': 5, 'distance': 2, 'loc': 5}
    # ]

it was messed up tabs and spaces like what was previously mentioned

Community
  • 1
  • 1
ThriceGood
  • 1,633
  • 3
  • 25
  • 43