2016-08-02 28 views
0

我正在面對腳本的深度麻煩,我試圖寫回答關於我正在做的課程的問題。我一直在得到SyntaxError:無效的語法行138,這有點奇怪。這是我的腳本。如果有人能夠解釋如何解決這個問題,那將是美好的。由於SyntaxError:無效語法行138意外錯誤

class Message(object): 

    def __init__(self, text): 

     self.message_text = text 
     self.valid_words = load_words(WORDLIST_FILENAME) 


    def get_message_text(self): 

     return self.message_text 


    def get_valid_words(self): 

     return self.valid_words[:] 

    def build_shift_dict(self, shift): 

     lc_str = string.ascii_lowercase 
     uc_str = string.ascii_uppercase 

     shifted_dict = {} 

  
     for ltr in lc_str: 
      if lc_str.index(ltr) + shift < 26: 
       shifted_dict[ltr] = lc_str[lc_str.index(ltr) + shift] 
      else: 
       shifted_dict[ltr] = lc_str[lc_str.index(ltr)-26+shift] 

     for ltr in uc_str: 
      if uc_str.index(ltr) + shift < 26: 
       shifted_dict[ltr] = uc_str[uc_str.index(ltr) + shift] 
      else: 
       shifted_dict[ltr] = uc_str[uc_str.index(ltr)-26+shift] 

     return shifted_dict 


    def apply_shift(self, shift): 

     cipher = self.build_shift_dict(shift) 
     ciphertext = "" 

     for char in self.message_text: 
      if char in cipher: 
       ciphertext = ciphertext + cipher[char] 
      else: 
       ciphertext = ciphertext + char 

     return ciphertext 
+2

這裏的線數遠遠少於138行。這些行中的其中一行代碼是否是第138行?如果是這樣,你能告訴我們哪個? – smarx

+2

你能給出確切的信息嗎?我們不知道第138行是什麼。 – idjaw

+0

請[edit]您的帖子爲我們提供[mcve]。 –

回答

1

這兩條線之間:

shifted_dict = {} 

for ltr in lc_str: 

你有一個非ASCII字符('\xe2')。刪除它。

(Python會告訴你如果你嘗試在Python解釋器中加載你的代碼。)

相關問題