|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
file_open and file_save
import easygui as G
import os
file_path = G.fileopenbox('选择要打开的文件夹','选择文件',default = '*.txt')
with open(file_path) as f:
title = os.path.basename(file_path)
file1 = f.read()
msg = '文件【%s】的内容如下:' % title
text = f.read()
file2 = G.textbox(msg, title, text)
if file1 != file2[:-1]:
choices = ['覆盖保存','放弃保存','另存为']
user_choice = G.buttonbox('是否保存',choices = choices)
if user_choice == choices[0]:
with open(file_path, 'w') as f:
f.write(file2[:-1])
if user_choice == choices[2]:
another_path = G.filesavebox('请选择新地址','另存为',default = '*.txt')
with open(another_path,'w') as new_file:
new_file.write(file2[:-1])
|
评分
-
查看全部评分
|