码迷,mamicode.com
首页 > 编程语言 > 详细

python读取txt大文件

时间:2018-11-29 23:19:46      阅读:558      评论:0      收藏:0      [点我收藏+]

标签:join   with   style   write   nbsp   text   pre   gui   box   

直接上代码:

技术分享图片
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

 

python读取txt大文件

标签:join   with   style   write   nbsp   text   pre   gui   box   

原文地址:https://www.cnblogs.com/yibeimingyue/p/10041461.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!