There is an indentation error that says expected an indented block

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • leiel huang
    New Member
    • Jan 2011
    • 1

    There is an indentation error that says expected an indented block

    There 's a indentation error but i don't know what's wrong with it.
    the error says

    File "./class_question. py", line 12
    self.dic = [] #array of hash tables for input data
    ^
    IndentationErro r: expected an indented block


    Code:
    #! /usr/bin/env python
    
    class Question:
    	#constructor	
    	dic
    	questions
    	answers
    	qANDa
    	vspace
    	
    	def __init__(self):
       	self.dic = []			#array of hash tables for input data
       	self.questions = []	#array for all questions
       	self.answers   = [] 	#array for corresponding answers    
       	self.qANDa		= []	#array of hash tables
       	self.vspace 	= "0.4in "
        
       def getRestrictions(self,filename):
       	print "Processing",filename
       
       def addquestion(self,questionstring):
    	   self.questions.append(questionstring)
    		
    	def addanswer(self,answerstring):
    		self.answers.append(answerstring)
    		
    	def addqANDa(self,questionstring, answerstring):
    		dictionary = {}
    		dictionary['question'] = questionstring
    		dictionary['answer']   = answerstring	   
    	   
    	   self.qANDa.append(dictionary)
    	
    		
    	def outputdata(filename):
    		questionfilename = "files/"+filename +"_questions.tex"
    		answerfilename   = "files/"+filename +"_answers.tex"
    	
    		questionFile  = open(questionfilename, "w")
    		answerFile    = open(answerfilename, "w")		
    		
    		for ques in self.questions:
    			questionFile.write(ques+"\n")
    			questionFile.write("\\vspace{"+self.vspace+"}")
    		
    		for answ in self.answers:
    			answerFile.write(answ)		
    
    		questionFile.close();
    		answerFile.close();
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Your indentation is not consistent. My preference is to use 4 spaces.

    Also - you don't need the trailing semi-colons at the end.

    Comment

    Working...