【发布时间】:2019-01-02 09:30:52
【问题描述】:
这里是 Python 菜鸟:
我正在尝试通过使用 tkinter 选择多个文本文件来加快文件编辑速度,但我不知道如何打开它们并一次编辑它们以删除 <_io.TextIOWrapper name='xyz.txt' mode='w' encoding='UTF-8'>
我的代码:
import re
from Tkinter import *
from tkFileDialog import askopenfilenames
filename = askopenfilenames()
f = open(filename, "r")
lines = f.readlines()
f.close()
f = open(filename, "w")
for line in lines:
line = re.sub('<(.|\n)*?>', "", line)
f.write(line)
f.close()
它适用于 askopenfilename(不是复数),我可以很好地删除不需要的字符串。
任何提示将不胜感激!
【问题讨论】:
标签: python regex python-3.x file tkinter