|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 YaoYan 于 2020-3-17 06:40 编辑
- import easygui as g
- import os
- dir_path=g.diropenbox()+'\\*.txt'
- file_path=g.fileopenbox(default=dir_path)
- file_name=os.path.basename(file_path)
- with open(file_path) as f:
- file_content=f.read()
- content_after=g.textbox(msg='文件【'+file_name+'】的内容如下:', title='显示文件内容', text=file_content)
- if file_content==content_after:
- g.msgbox('再见^_^')
- else:
- choice=g.buttonbox(msg='检测到文件内容发生改变,请选择一下操作',title='警告',choices=('覆盖保存','放弃保存','另存为'))
- if choice=='覆盖保存':
- file_content=content_after
- with open(file_path,'w') as cover:
- cover.write(file_content)
- elif choice=='放弃保存':
- pass
- elif choice=='另存为':
- save_dir=g.diropenbox()
- file_content=content_after
- with open(save_dir,'w') as save:
- save.write(file_content)
复制代码
这是我的代码,但是当我点击另存为的时候会报错, 如下:
- File "C:/python/work35/3.py", line 23, in <module>
- with open(save_dir,'w') as s:
- PermissionError: [Errno 13] Permission denied: 'C:\\python\\work35'
复制代码
这个该怎么解啊
with open(save_dir,'w') as save,save_dir是文件夹名,不是文件名,你得加上一个文件名才行。
|
|