Python基础(3)——文件操作、三元表达式&列表生成式、集合、json操作、函数

时间:2020-09-03 16:57:46   收藏:0   阅读:64

目录:

一、文件操作

二、三元表达式&列表生成式

三、集合

四、json操作

五、函数

 

正文:

一、文件操作2

1、自动关闭文件

with open(xxx) as x:
# f=open(‘a.txt‘)
# f.close()

#代替以上代码

#文件用完自动关闭
with open(user.txt,encoding=utf-8) as f:
    result = f.read()

 

2、大文件的读取

txt内容:

ds,456789

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!