indentation error

asit lipun4u at gmail.com
Fri Mar 5 09:04:13 CET 2010


Consider the following code

import stat, sys, os, string, commands

try:
    pattern = raw_input("Enter the file pattern to search for :\n")
    commandString = "find " + pattern
    commandOutput = commands.getoutput(commandString)
    findResults = string.split(commandOutput, "\n")
    print "Files : "
    print commandOutput
    print "============================="
    for file in findResults:
        mode = stat.S_IMODE(os.lstat(file)[stat.ST_MODE])
        print "\nPermissions for file", file, ":"
        for level in "USR", "GRP", "OTH":
            for perm in "R", "W", "X":
                if mode & getattr(stat,"S_I"+perm+level):
                    print level, " has ", perm, " permission"
                else:
                    print level, " does NOT have ", perm, "
permission"
except:
    print "There was a problem - check the message above"


According to me, indentation is ok. but the python interpreter gives
an indentation error

[asit ~/py] $ python search.py
  File "search.py", line 7
    findResults = string.split(commandOutput, "\n")
                                                  ^
IndentationError: unindent does not match any outer indentation level



More information about the Python-list mailing list