2
对于下面的函数,我没有收到任何错误,但没有文件出现在与保存.py的目录相同的目录中。有没有人有任何想法,为什么这是?Python 3:用.write不返回目录中的任何文件
import itertools
TAG_RE = re.compile(r'<[^>]+>')
def remove_tags(text):
return TAG_RE.sub('', text)
def get_rid_of_html():
print("removing html tags")
with open('messages.htm', "r", encoding="utf8") as f:
lines = f.read()
print(len(lines))
lines_removed_html = remove_tags(lines)
with open('messages_txt_remove_list.txt', 'w', encoding="utf8") as f:
f.write(lines_removed_html)
get_rid_of_html()
嘿Alecxe。是的,我调用了get_rid_of_html()函数。 –
请显示编译'TAG_RE'的地方。 – Signal
检查当前工作目录:'import os os.getcwd()'其中'open()'用于调用它时的相对路径。 – Parfait