print会自动添加换行符
其它的,没什么区别。有时候为了使用灵活,才会这么用。

例如你想把print的内容写向一下log文件,你可以这么做

stdout_bk = sys.stdout  #备份一下标准输出
sys.stdout = open("aa.log", "w") #标准输出重定向到一个文件

这样子,print的内容就会全部输向xx.log
 flog = open("xx.log", "w")

print >> flog, "sth. to print"

建议用这种形式的重定向
一是,所见即所得
二是,不用备份系统的标准输出 

相关文章:

  • 2021-04-10
  • 2021-05-20
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-24
  • 2021-07-16
  • 2021-11-11
相关资源
相似解决方案