1. 新建一个txt文件,将生词表从pdf复制粘贴进来
2. 依次使用3次正则表达式替换
- 第一次 ``` ^(.*?) –
或者
(?<=\n)(.*?) –
```bash
<span>\1</span>\t
防止弹出2个窗口
root = Tk() root.withdraw()
try: with open(‘esl.txt’, encoding=”utf-8”) as f: contents = f.read() except FileNotFoundError: messagebox.showerror(“错误”,”esl.txt 文件不存在!”) else: contents = re.sub(r’^(.?) – ‘, r’\1\t’, contents) contents = re.sub(r’(?<=\n)(.?) – ‘, r’\1\t’, contents) contents = re.sub(r’\n([^*<])’, r’ \1’, contents) contents = re.sub(r’\n*\s’, r’\t’, contents)
with open('esl_new.txt', 'w', encoding="utf-8") as f:
f.write(contents)
messagebox.showinfo("完成","好了,骚年!")
<a name="gXWRh"></a>
### 4. 打包成exe
安装pyinstaller
```bash
pip3 install pyinstaller
打包
# 打包exe
pyinstaller -F setup.py
# 不带控制台的打包
pyinstaller -F -w setup.py
# 打包指定exe图标打包
pyinstaller -F -i xx.ico setup.py