Python在二进制文件中搜索和替换
发布时间:2020-12-16 23:09:40 所属栏目:Python 来源:网络整理
导读:我试图在这个pdf格式文件(header.fdf,我推测这被视为二进制文件)中搜索和替换一些文本(例如“Smith,John”): '%FDF-1.2n%xe2xe3xcfxd3n1 0 objn/FDF/Fields[/V(M)/T(PatientSexLabel)/V(24-09-1956 53)/T(PatientDateOfBirth)/V(Fisher)/T(PatientLa
我试图在这个pdf格式文件(header.fdf,我推测这被视为二进制文件)中搜索和替换一些文本(例如“Smith,John”):
'%FDF-1.2n%xe2xe3xcfxd3n1 0 objn<</FDF<</Fields[<</V(M)/T(PatientSexLabel)>><</V(24-09-1956 53)/T(PatientDateOfBirth)>><</V(Fisher)/T(PatientLastNameLabel)>><</V(CNSL)/T(PatientConsultant)>><</V(28-01-2010 18:13)/T(PatientAdmission)>><</V(134 Field StreetrBlackburn BB1 1BB)/T(PatientAddressLabel)>><</V(Smith,John)/T(PatientName)>><</V(24-09-1956)/T(PatientDobLabel)>><</V(0123456)/T(PatientRxr)>><</V(01234567891011)/T(PatientNhsLabel)>><</V(John)/T(PatientFirstNameLabel)>><</V(0123456)/T(PatientRxrLabel)>>]>>>>nendobjntrailern<</Root 1 0 R>>n%%EOFn' 后 f=open("header.fdf","rb") s=f.read() f.close() s=s.replace(b'PatientName',name) 发生以下错误: Traceback (most recent call last): File "/home/aj/Inkscape/Med/GAD/gad.py",line 56,in <module> s=s.replace(b'PatientName',name) TypeError: expected an object with the buffer interface 怎么最好这样做? 解决方法f=open("header.fdf","rb") s=str(f.read()) f.close() s=s.replace(b'PatientName',name) 要么 f=open("header.fdf",bytes(name)) 可能是后者,因为我不认为你将能够使用unicode名称与这种类型的替代 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- 你如何在python中使用jsbeautifier解压缩javascr
- 使用sklearn和线性回归时出错:shape(1,16)和(1,
- import pyttsx在python 2.7中工作,但不在python3
- python – 为什么在tensorflow中构建resnet模型
- Python实现按特定格式对文件进行读写的方法示例
- python – 从scipy optimize.least_squares方法获
- Python:从字典中替换文本文件中的多个单词
- 在Django的模型中执行原始SQL查询的方法
- 无法理解Python 2.7中的阶乘的经典递归示例
- linux下通过python获得指定网卡的ip地址
热点阅读