Unindent does not match any outer indentation level?
Question: > **Possible Duplicate:**  
>  [IndentationError: unindent does not match any outer indentation
> level](http://stackoverflow.com/questions/492387/indentationerror-unindent-
> does-not-match-any-outer-indentation-level)

I have the following python code.

    
    
    import sys
    
    ins = open( sys.argv[1], "r" )
    array = []
    for line in ins:
        s = line.split()
        array.append( s[0] ) # <-- Error here 
    print array
    
    ins.close()
    

The python interpreter complains

    
    
      File "sort.py", line 7
        array.append( s[0] )
                           ^
    IndentationError: unindent does not match any outer indentation level
    

Why so? And how to correct this error?


Answer: You are mixing tabs and spaces (happens sometimes :). Use one or the other.

I looked at your source:

    
    
        s = line.split()  # there's a tab at the start of the line
        array.append( s[0] )  # spaces at the start of the line
    

* * *

Aside: As just a friendly suggestion, consider using `with` to open your file.
The advantage is that the file will be automatically closed for you (no
`close()` needed) when you are done or an exception is encountered.

    
    
    array = []
    with open( sys.argv[1], "r" ) as ins:  # "r" really not needed, it's the default.
       for line in ins:
          s = line.split()
          # etc...
    

