python 利用split讀取文本文件中每一行的數字並保存至相應文件夾


import re
from numpy import *
def getStr(file_path,file_path1):
    fp = open(file_path, 'r')
    op = open(file_path1,'w')
    for eachline in fp.readlines():
        lines = re.split("\t| |\n",eachline)
        print(lines[2:10])
        newlines=lines[2:10]
        i = 0   
        for s in newlines:
            i=i+1
            if i<8:
                print(s)
                op.write(s+',')                        
            elif i==8:
                op.write(s+'\n')
                continue      
            else: 
                break    
    fp.close()
    op.close()

if __name__ == '__main__':
    for i in range(483):
        getStr(str(i)+'.txt','result/'+str(i)+'.txt')

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM