Why Am I Getting "Indentationerror: Expected an Indented Block"? [Duplicate]
If Len(Trashed_Files) == 0: Print "No Files Trashed from Current Dir ('%S')" % Os. Path. Realpath(Os. Curdir) Else: Index=Raw_Input("What File to Restore [0...
if len(trashed_files) == 0 :
print "No files trashed from current dir ('%s')" % os.path.realpath(os.curdir)
else :
index=raw_input("What file to restore [0..%d]: " % (len(trashed_files)-1))
if index == "*" :
for tfile in trashed_files :
try:
tfile.restore()
except IOError, e:
import sys
print >> sys.stderr, str(e)
sys.exit(1)
elif index == "" :
print "Exiting"
else :
index = int(index)
try:
trashed_files[index].restore()
except IOError, e:
import sys
print >> sys.stderr, str(e)
sys.exit(1)
I am getting:
elif index == "" :
^
IndentationError: expected an indented block
6 Answers
As the error message indicates, you have an indentation error. It is probably caused by a mix of tabs and spaces.
There are in fact multiples things you need to know about indentation in Python:
Must Read
Python really cares about indention.
In a lot of other languages the indention is not necessary but improves readability. In Python indentation replaces the keyword begin / end or { } and is therefore necessary.
This is verified before the execution of the code, therefore even if the code with the indentation error is never reached, it won't work.