|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
课后作业035讲动动手35题,为什么我这样写,选择另存为的时候文件保存不了?
- import os
- import easygui as g
- file_name = input('请输入你需要打开文件的地址:')
- f = open(file_name, 'r+')
- neirong = f.read()
- f.close()
- name = os.path.basename(file_name)
- msg = '文件【%s】的内容如下:' % name
- f1 = g.textbox(msg, title='显示文件内容', text=neirong)
- if f1 != neirong:
- msg = '检测到文件内容发生改变,请选择以下操作:'
- choose = g.buttonbox(msg, title='', choices=['覆盖保存', '放弃保存', '另存为'])
- if choose == '覆盖保存':
- f = open(file_name, 'w')
- f.write(f1)
- f.close()
- elif choose == '放弃保存':
- pass
- elif choose == '另存为':
- g.filesavebox(title='另存为', default='.txt', filetypes=['*.txt'])
复制代码
- import os
- import easygui as g
- file_name = input('请输入你需要打开文件的地址:')
- f = open(file_name, 'r+')
- neirong = f.read()
- f.close()
- name = os.path.basename(file_name)
- msg = '文件【%s】的内容如下:' % name
- f1 = g.textbox(msg, title='显示文件内容', text=neirong)
- if f1 != neirong:
- msg = '检测到文件内容发生改变,请选择以下操作:'
- choose = g.buttonbox(msg, title='', choices=['覆盖保存', '放弃保存', '另存为'])
- if choose == '覆盖保存':
- f = open(file_name, 'w')
- f.write(f1)
- f.close()
- elif choose == '放弃保存':
- pass
- elif choose == '另存为':
- file = g.filesavebox(title='另存为', default='.txt', filetypes=['*.txt'])
- f = open(file, 'w')
- f.write(f1)
- f.close()
复制代码
|
|