作者opiumeater (opiumeater)
看板Python
标题[闲聊] 新发现print >>的用法
时间Wed Mar 23 22:47:54 2011
今天才发现原来print可以这样用:
f = open('txt','w')
for i in range(10):
print >> f,i
我以前都会写成
f = open('txt','w')
a = map(str, range(10))
txt = '\n'.join(a)
f.write(txt)
f.close()
比较起来第一个好多了,跟大家分享。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 123.193.213.133
2F:→ drjoey:虽然我也常常 print 到 sys.stderr ... 03/23 23:48