1. 程式人生 > >python讀取txt大檔案

python讀取txt大檔案

直接上程式碼:

import easygui
import os
s4 = []
s6 = []
path = easygui.fileopenbox()
if path:
    b = os.path.splitext(path)
    c = [b[0], '_trace', '.xyz']
    d = ''.join(c)
    with open(d, 'w+') as f1:
        with open(path, 'r', encoding='utf-8') as f:
            for line in f:
                s1 
= line.strip() s2 = (s1.strip().split(' ')[-6:-3][::-1]) s3 = ' '.join(s2) f1.writelines(s3) f1.writelines('\n')
View Code