2017-06-12 62 views
0

當我將下面的代碼粘貼到我的python shell中時。我收到一個縮進錯誤。Django Python shell縮進錯誤

... print "this is an ideal answer for both" File "", line 2 print "this is an ideal answer for both" ^IndentationError: expected an indented block

def get_match(user_a, user_b): 
    user_a_answers = UserAnswer.objects.filter(user=user_a)[0] 
    user_b_answers = UserAnswer.objects.filter(user=user_b)[0] 
    if user_a_answers.question.id == user_b_answers.question.id: 
     user_a_answer = user_a_answers.my_answer 
     user_a_pref = user_a_answers.their_answer 
     user_b_answer = user_b_answers.my_answer 
     user_b_pref = user_b_answers.their_answer 
     if user_a_answer == user_b_pref: 
      print "%s fits with %s's preference" %(user_a_answers.user.username, user_b_answers.user.username) 
     if user_a_pref == user_b_answer: 
      print "%s fits with %s's preference" %(user_a_answers.user.username, user_b_answers.user.username) 
     if user_a_answer == user_b_pref and user_a_pref == user_b_answer: 
      print "this is an ideal answer for both" 




get_match(mohit, saraswati) 
get_match(saraswati, userc) 
get_match(mohit, userc) 

我得到一個壓痕錯誤,當我從外殼,運行這是爲什麼呢?`

回答

0

這是很難確定的縮進錯誤。因爲Python支持單向縮進。您可能一次使用Tab和空格。請自行檢查並一次僅使用一個。建議使用空格。

+0

相同的代碼在不同的shell中運行,而我得到 – Raghu

+0

你試過從文件運行這個嗎? –