2017-03-02 44 views
0

我很抱歉,但我有不明白的問題...Python的預期誤塊

def login_screen(): 
    print(30 * "-") 
    print(" LOGIN") 
    print(30 * "-") 
    username = print("Please enter your username: ") 
    password = print("Please enter your password: ") 
     with open('logins.txt', 'r') as csvfile: 
      loginreader = csv.reader(csvfile, delimiter=',', quotechar= None) 
      for codes in loginreader: 
       if len(codes) == L_LEN: 
        if codes[L_USERNAME] == username and codes[L_PASSWORD] == password and codes[L_ADMIN] == "Yes": 
         admin_console() 
        elif username == row[L_USERNAME] and password == row[PASSWORD] and row[L_ADMIN] == "No": 
         #Temp normal console here 
        else: 
         clearscreen() 
         error_head() 
         print("Unknown account") 
         input("Press [ENTER] To continue...") 
         login_screen() 
       elif len(codes) != M_LEN: 
        next(csvfile, None) 

所以問題是,它配備了以下錯誤:

File "G:\Python\DatabaseStandardRewrite\Login.py", line 49 
else: 
^

IndentationError:預計一個縮進塊

但我不明白! (是的,所有其他的事情都是在文檔的其餘部分定義

請問你們誰看到我的錯誤

納坦

+0

我在我的代碼,而不是在這個網站? –

+0

那麼它可能TAB /空間混淆。將製表符轉換爲空格並檢查輸出。 –

+0

我該怎麼做(是的,我是Python新手) –

回答

2

的Python不允許塊爲空;!?你至少需要一個語句,註釋不計,因此在elif塊之前你else,你應該把pass

  elif username == row[L_USERNAME] and password == row[PASSWORD] and row[L_ADMIN] == "No": 
       #Temp normal console here 
       pass 
      else: 
       clearscreen() 
+0

哦!天才!謝謝! –

+0

如果這是正確答案,請接受它作爲正確答案。 – Chris

+0

在這種情況下,由於條件語句在一個循環中,因此如果您想直接跳到循環的下一次迭代,您也可以使用'continue'使'elif'塊不爲空。在這個例子中,它最終是等價的,因爲'pass'後面沒有別的事情發生(其他條件分支不適用)。 – berna1111