作者uranusjr (←这人是超级笨蛋)
看板Python
标题Re: [闲聊] 新发现print >>的用法
时间Thu Mar 24 02:55:56 2011
※ 引述《opiumeater (opiumeater)》之铭言:
: 今天才发现原来print可以这样用:
: f = open('txt','w')
: for i in range(10):
: print >> f,i
这个印完还是要 close 吧...
with open('txt', 'w') as f:
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: 114.32.81.146
1F:→ opiumeater:没错,我忘了用with,感谢 03/24 23:08