By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,550 Members | 1,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,550 IT Pros & Developers. It's quick & easy.

There is an indentation error that says expected an indented block

P: 1
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
^
IndentationError: expected an indented block


Expand|Select|Wrap|Line Numbers
  1. #! /usr/bin/env python
  2.  
  3. class Question:
  4.     #constructor    
  5.     dic
  6.     questions
  7.     answers
  8.     qANDa
  9.     vspace
  10.  
  11.     def __init__(self):
  12.        self.dic = []            #array of hash tables for input data
  13.        self.questions = []    #array for all questions
  14.        self.answers   = []     #array for corresponding answers    
  15.        self.qANDa        = []    #array of hash tables
  16.        self.vspace     = "0.4in "
  17.  
  18.    def getRestrictions(self,filename):
  19.        print "Processing",filename
  20.  
  21.    def addquestion(self,questionstring):
  22.        self.questions.append(questionstring)
  23.  
  24.     def addanswer(self,answerstring):
  25.         self.answers.append(answerstring)
  26.  
  27.     def addqANDa(self,questionstring, answerstring):
  28.         dictionary = {}
  29.         dictionary['question'] = questionstring
  30.         dictionary['answer']   = answerstring       
  31.  
  32.        self.qANDa.append(dictionary)
  33.  
  34.  
  35.     def outputdata(filename):
  36.         questionfilename = "files/"+filename +"_questions.tex"
  37.         answerfilename   = "files/"+filename +"_answers.tex"
  38.  
  39.         questionFile  = open(questionfilename, "w")
  40.         answerFile    = open(answerfilename, "w")        
  41.  
  42.         for ques in self.questions:
  43.             questionFile.write(ques+"\n")
  44.             questionFile.write("\\vspace{"+self.vspace+"}")
  45.  
  46.         for answ in self.answers:
  47.             answerFile.write(answ)        
  48.  
  49.         questionFile.close();
  50.         answerFile.close();
  51.  
Jan 12 '11 #1
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
Your indentation is not consistent. My preference is to use 4 spaces.

Also - you don't need the trailing semi-colons at the end.
Jan 12 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.