首页 > 编程语言 > 详细

python2处理表格文件按照规则多行输出(中文路径,print)

时间:2021-06-21 11:40:17      阅读:26      评论:0      收藏:0      [点我收藏+]
 1 #!/usr/bin/python
 2 # -*- coding: UTF-8 -*-
 3 
 4 #python2支持print带入参
 5 from __future__ import print_function
 6 # python2使用utf-8编码解决中文路径问题
 7 from __future__ import unicode_literals 
 8 import os, sys, json, getopt, re
 9 #在python3中不需要设置也可以支持中文路径
10 reload(sys) 
11 sys.setdefaultencoding(utf-8)
12 
13 class printTableFunc(object):
14     def __init__(self, file, fileList = [], fileDir = {}):
15         self.process(file, fileList, fileDir)
16                    
17     def process(self, file, fileList, fileDir):
18         with open(file, rw) as fr:
19             # print fr.name
20             data = fr.readline()
21             print ("//"+data)
22             lines = fr.readlines()
23             for line in lines:
24                 line = line.strip(\n\r)
25                 # print line
26                 fileList.append({+line+}, )
27         fr.close()
28 
29 if __name__ == __main__:
30     tableFile = /测试中文路径/test.csv
31     fileList = []
32     fileDir = {}
33 
34     printTableFunc(tableFile, fileList, fileDir)
35     i = 0
36     for file in fileList:
37         i = i + 1
38         if (0 == i % 7):
39             print(file)
40         else:
41             print(file, end=‘‘)

 

python2处理表格文件按照规则多行输出(中文路径,print)

原文:https://www.cnblogs.com/Lunais/p/14904586.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!