繁体   English   中英

打印循环到终端的同一行

[英]Print loop to the same line in terminal

这是一些代码。 这应该是不言自明的。 但无论如何,我们走了。

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

除了代替它打印行以外,所有作品都可以

wrong: pass
wrong: pass
wrong: pass

在找到密码匹配之前,是否可以在同一行上打印?

在Python中,一个,在print语句的结束,防止线路中断,从而防止下一个文本在新行打印。 所以,

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

这将在同一行中打印所有文本,直到密码正确为止

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM