1 Star 0 Fork 0

Riggle_001/HSS_data

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
typora2jianshu.py 1.00 KB
一键复制 编辑 原始数据 按行查看 历史
import re
import chardet
txt = input('请输入您要转换的txt文件名:')
def typora2jianshu(txt):
try:
with open(txt+'.txt','rb') as f:
pre_string = f.read()
f_charInfo = chardet.detect(pre_string)
#print(f_charInfo) # 输出文本格式信息
print('此文本的编码方式为:',f_charInfo['encoding']) # 取得文本格式
string = pre_string.decode(f_charInfo['encoding']) # 通过取得的文本格式读取txt
except:
print('恭喜你遇到了未知错误,联系文科数据员debug吧')
pa0= r'<img src=\"' # 问题一:图片转义不识别
f0 = re.sub(pa0,'![image](',string)
pa1 = r'\" alt=\"文科数据员图片\" />'
f1 = re.sub(pa1,')',f0)
with open('ed_'+txt+'.txt', 'w',encoding='{}'.format(f_charInfo['encoding'])) as n: # 设置文件对象
n.write(f1) # 将字符串写入文件中
print('已经完成写入,文件名为{}'.format('ed_'+txt+'.txt'))
typora2jianshu(txt)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/riggle_001/HSS_data.git
git@gitee.com:riggle_001/HSS_data.git
riggle_001
HSS_data
HSS_data
master

搜索帮助