2015-08-21 58 views
0

以下是一些代碼。它應該是自我解釋的。但無論如何,我們走了。打印循環到終端中的同一行

try: 
     smtpserver.login(user, password) 
     print "password is: %s" % password 
     break; 
    except smtplib.SMTPAuthenticationError: 
     print "wrong: %s" % password 

所有作品,除了外商投資企業,而不是像

wrong: pass 
wrong: pass 
wrong: pass 

印刷生產線是否有可能直到密碼找到匹配在同一行打印?

回答

3

在python中,打印語句結尾的,可防止換行,從而防止以新行打印下一個文本。所以,

try: 
    smtpserver.login(user, password) 
    print "password is: %s" % password 
    break; 
    except smtplib.SMTPAuthenticationError: 
    print "wrong: %s" % password, 

這將打印在同一行中的所有文本,直到密碼正確

+0

謝謝:3,現在我的腳本看起來更好 –

+0

@MichaelDarnell:高興幫助。如果它對您有用,請隨時接受我的回答。 –

+0

有沒有辦法在原始文件上打印一次? –