作者leeraphael (leeraphael)
看板CodeJob
标题Re: [讨论] 修改CSV格式 请问这样值多少钱?
时间Fri Dec 2 09:17:15 2011
贴一下,python的版本
不知道还有没有更精简的方法
不过也真的是一顿饭就很多了,没几分钟的code
#--------Code Start----------------------
inputfd = file("testdata.txt", 'r')
outputfd = file("testdata_result.txt", 'w')
while 1:
line = inputfd.readline()
if not line:
break
line = line.replace('\r', '')
line = line.replace('\n', '')
line = line.split(' ')
for x in line:
try:
outputfd.write("%s\n" % int(x,10))
except:
continue
inputfd.close()
outputfd.close()
#--------Code End----------------------
FYI.
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 221.120.66.203
1F:推 deo2000:板上都好强! 虽然我觉得不难,但还是要写很久 12/02 09:18
※ 编辑: leeraphael 来自: 60.251.231.82 (12/02 09:36)
2F:推 litleaf:还是 python 看起来比较亲切 像在说话一样 12/02 09:48
3F:推 LaPass:Java: 12/02 11:21
4F:→ LaPass:new 读取档案("test.txt").取得内容().再把空格换成换行(). 12/02 11:21
5F:→ LaPass:把档案存回去(); 12/02 11:22
6F:→ LaPass: ※可执行 12/02 11:22
7F:推 LaPass:linux好像可以打个指令应该就能直接取代文挡中的字了 12/02 11:25