1,需要依赖的jar包, <!-- POI(operate excel) start --> <!-- the version of the following POI packages must be consistent --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.17&
读取csv文件: def readCsv(): rows=[] with file(r'E:\py\py01\Data\system.csv','rb') as f: reads=csv.reader(f) for i in reads: rows.append(i) print rows return rows写入csv文件: def writer(): with file(r'E:\py\py01\Data\system.csv','wb') as f: writer=csv.writer(
# -*- coding: utf-8 -*- #spyder (python 3.7) 1. 统计字符(可以在jieba分词之后使用) from collections import Counter from operator import itemgetter # txt_list可以写成函数参数进行导入 txt_list = ['千古','人间','人间','龙','龙','龙','哈哈哈','人才','千古','千古'] c = Counter() for x in txt_list:
第一种.用for循环不断打开文件写入关闭 测试代码数据如下: import time begin = time.perf_counter() def a(f, lis): f.write(lis + '\n') lis = 'hello' lis2 = 'hello2' for i in range(100): with open('ces.txt', 'a+')as f: # 写入文件 a(f, lis) for j in range(10): with open('ces.txt', 'a+