1、环境
Windows 7或Windows 10+ Python3.7
2、代码
'''
Function: 将手机联系人备份从vCard3.0文件转为vCard2.1文件(旧式手机需要)
Comment: 在Python3.7下可运行,不支持头像转换。
DATE: 2019-01-23
Author: me
'''
import pdb
def str_to_hex(str_to_chg):
'''将string转换成hex形式的string(参考Quoted-printable编码)'''
tmp_bytes = bytes(str_to_chg, encoding = 'utf-8')
tmp_chars = []
for each_byte in tmp_bytes:
tmp_chars.append( '=' + str(hex(int(each_byte))).replace('0x','').upper())
return ''.join(tmp_chars)
fp = r'D:\Contact3.0.vcf'
wfile = r'D:\Contact2.1.vcf'
wf = open(wfile,'w')
try:
with open(fp, 'r') as file:
all_content = file.readlines()
ignore_lines = 0
#pdb.set_trace()
for line in