|
2鱼币
text 是读取打开文件的内容 text_ after 是显示文本里面用了text的内容这两个不应该相等吗?
这个 text !=text_after是真的搞不懂?
小甲鱼的原本的意思应该是比较前后文本是否一致在来判断是否进行覆
- import easygui as g
- import os
- file_path = g.fileopenbox(default="*.txt")
- with open(file_path) as old_file:
- title = os.path.basename(file_path)
- msg = "文件【%s】的内容如下:" % title
- text = old_file.read()
- text_after = g.textbox(msg, title, text)
- # text 是读取打开文件的内容 text_ after 是显示文本里面用了text的内容这两个不应该相等吗?
- if text != text_after:
- choice = g.buttonbox("检测到文件内容发生改变,请选择以下操作:", "警告", ("覆盖保存", "放弃保存", "另存为..."))
- if choice == "覆盖保存":
- with open(file_path, "w") as old_file:
- old_file.write(text_after[:-1])
- if choice == "放弃保存":
- pass
- if choice == "另存为...":
- another_path = g.filesavebox(default=".txt")
- if os.path.splitext(another_path)[1] != '.txt':
- another_path += '.txt'
- with open(another_path, "w") as new_file:
- new_file.write(text_after[:-1])
复制代码 盖等操作
# text 是读取打开文件的内容 text_ after 是显示文本里面用了text的内容这两个不应该相等吗?
没错是相等啊,只要你打开后在textbox内没改动文件内容就是相等的就不用重新保存
|
最佳答案
查看完整内容
没错是相等啊,只要你打开后在textbox内没改动文件内容就是相等的就不用重新保存
|