Re: [閒聊] 新發現print >>的用法

看板Python作者 (←這人是超級笨蛋)時間14年前 (2011/03/24 02:55), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串2/3 (看更多)
※ 引述《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

03/24 23:08, , 1F
沒錯,我忘了用with,感謝
03/24 23:08, 1F
文章代碼(AID): #1DYa8-c6 (Python)
討論串 (同標題文章)
本文引述了以下文章的的內容:
以下文章回應了本文
完整討論串 (本文為第 2 之 3 篇):
文章代碼(AID): #1DYa8-c6 (Python)