|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #035 作业2
- import easygui as g
- file_path = g.fileopenbox()
- file1 = open(file_path,'r',encoding = 'UTF-8')
- #with open(file_path,'r',encoding = 'UTF-8') as file1
- content = []
- for each_line in file1:
- content.append(each_line)
- g.textbox(text=content,title='显示文件内容',msg='文件'+file_path+'的内容显示如下:')
复制代码
读文件时,用file1 = open()没问题,用with open as f(如下一行的注释所示)就会报错,请问为什么?
使用平台及版本:3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)]
python版本:Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
(问题出现在035讲的课后题,之前用with open as f 没问题)
这是语法问题
- # coding:utf8
- #035 作业2
- import easygui as g
- file_path = g.fileopenbox()
- #file1 = open(file_path,'r',encoding = 'UTF-8')
- with open(file_path,'r',encoding = 'UTF-8') as file1:
- content = []
- for each_line in file1:
- content.append(each_line)
- g.textbox(text=content,title='显示文件内容',msg='文件'+file_path+'的内容显示如下:')
复制代码
|
|