Re: [問題] 如何讀取txt檔中的資料並寫入另一個txt檔?
with open('1.txt','r') as in_f:
with open('2.txt','w') as out_f:
for line in in_f:
print line;
try:
mylist = line.split(" ")
if len(mylist) >= 3:
out_f.writelines(mylist[0] + " " + mylist[2])
else:
print "not 3 items"
except Exception, e:
print "error: " + str(e)
--
聽好了,你在想這些無聊事的時候,時間正一刻一刻地從我們身旁流過...
這些流過的時間不只是你的生命,也是我的生命啊!
── 炎尾燃
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 131.204.39.159
推
08/04 23:35, , 1F
08/04 23:35, 1F
→
08/04 23:35, , 2F
08/04 23:35, 2F
→
08/05 00:13, , 3F
08/05 00:13, 3F
推
08/05 15:48, , 4F
08/05 15:48, 4F
→
08/06 04:12, , 5F
08/06 04:12, 5F
應觀眾要求重排一次 ^^;
※ 編輯: Starwindd 來自: 131.204.39.159 (08/06 04:16)
討論串 (同標題文章)