![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
文件读写
读写各类文件的基本操作
大小瓶
这个作者很懒,什么都没留下…
展开
-
pickle读写文件
import pickleclass person():def init(self,name):self.name = namezs = person(‘张三’)#写入with open(‘1.map’, ‘wb’) as f:pickle.dump([{‘zs’:zs}], f)#读取(需要载入类)with open(‘1.map’, ‘rb’) as f:res = pickle.load(f)print(res[0][‘zs’].name)...原创 2021-04-14 17:27:14 · 114 阅读 · 0 评论 -
python读取配置文件
import configparsercf = configparser.ConfigParser()#配置文件在当前文件的上上级目录下cf.read(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), '1.conf'))base_path = cf.get('path', 'base_path')配置文件形式...原创 2020-07-14 13:11:32 · 131 阅读 · 0 评论 -
python读取pptx
安装库pip install python-pptx读取文字、表格、图片from pptx import Presentationfrom docx import Documentfrom pptx.shapes.picture import Picturedoc = Document()prs = Presentation("1.pptx")index = 1#读取幻灯片的每一页for slide in prs.slides: # 读取每一板块 for shape原创 2020-07-12 00:08:11 · 1817 阅读 · 0 评论 -
读取docx,doc文件
安装docx模块pip install python-docx按顺序读取表格和段落from docx import Documentfrom docx.oxml.text.paragraph import CT_Pfrom docx.oxml.table import CT_Tblfrom docx.table import Tablefrom docx.text.paragraph import Paragraphpath = '1.docx' #文件路径document = Doc原创 2020-07-10 14:05:02 · 731 阅读 · 0 评论 -
python读xlsb
from pyxlsb import open_workbook as xlsb#读# 获取xslb 的第一张表with xlsb('1.xlsb').get_sheet(1) as data: # 按行获取数据 for row in data.rows(): # 读取每行单元格内位置 和 数据 for ro in row: # 得到 list 的数据 print(ro.v)...原创 2020-06-14 16:18:48 · 1720 阅读 · 0 评论 -
python读写xml
【代码】python读写xml。原创 2020-06-14 16:17:34 · 117 阅读 · 0 评论 -
python读写xlsx
【代码】python读写xlsx。原创 2020-06-14 16:16:35 · 393 阅读 · 0 评论 -
python读写xls
from xlwt import Workbookimport xlrd as xl#写wb = Workbook(encoding='utf-8')sheet1 = wb.add_sheet('Sheet_1')sheet1.write(0, 0, "1")sheet1.write(0, 1, "2")sheet1.write(1, 0, "3")sheet1.write(1, 1, "4")wb.save('1.xls')#读xls_file=xl.open_workbo原创 2020-06-14 16:15:19 · 664 阅读 · 0 评论 -
python读写json
import json#写with open('1.json','w',encoding='utf-8') as fp: json.dump([{'a': 1}, {'b': 2}], fp, ensure_ascii=False, indent=4) # json.dump({'a': 1}, fp, ensure_ascii=False, indent=4)#读with open('1.json',encoding='utf-8') as fp: a=json.loa原创 2020-06-14 16:14:11 · 612 阅读 · 0 评论 -
python读写csv
import csv#写with open('1.csv', 'w', encoding='utf-8', newline='') as csvfile:# with open('1.csv', 'a', encoding='utf-8', newline='') as csvfile: f = csv.writer(csvfile) # f.writerows([['a','b'],['c','d']]) f.writerow(['a','b'])#读with ope原创 2020-06-14 16:12:58 · 281 阅读 · 0 评论 -
python读写txt
#写f = open('1.txt', 'w', encoding='utf-8')f.write('1\n2')f.close()#读#f.readlines()#while True 配合f.readline()f = open('1.txt', 'r', encoding='utf-8')#还可以使用这两个方法t = f.read()print(t.split('\n'))f.close()原创 2020-06-14 16:11:58 · 144 阅读 · 0 评论 -
python读写视频
使用opencv库只能读图像,目前不支持音频,要合入音频可以结合moviepy使用获取视频基本信息import cv2#捕获视频cap = cv2.VideoCapture('2.avi')#视频信息#帧率:每秒播放的图片数fps = cap.get(cv2.CAP_PROP_FPS)print('帧率:',fps) #帧率:17.109959464313203width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)prin原创 2020-06-13 13:57:14 · 1464 阅读 · 0 评论