用法:把程序放在某个目录下,在相应目录下建一个"orginal"文件夹,把原始数据放进去;再建一个"processed"文件夹。
修改程序里面的判断条件什么的,然后运行就好了。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
# Transcribe is used to single out the interested rows
def transcribe(fname):
finname = "Original/"+fname
foutname = "Processed/Data_"+fname
fin = open(finname,"r")
fout = open(foutname,"w")
line = fin.readline()
# Find the first line of data
while line.strip().split('t')[0] <> 'Number':
line = fin.readline()
while line:
fout.write(line.strip().split('t')[0]+'t'+line.strip().split('t')[3]+"n"),
# line.srip().split() is used to select the desired rows separated by tab
line = fin.readline()
fin.close
fout.close
print 'Transcription of %s completed.' %finname[9:]
# Traverse all the files in the folder
currentdir = os.getcwd()+'\Original'
directory = os.listdir(currentdir)
for filename in directory:
transcribe(filename)
process.py
https://blog.sciencenet.cn/blog-270448-946670.html
上一篇:
资格考试回忆下一篇:
甲卡西酮的诞生——一点历史钩沉