码迷,mamicode.com
首页 > 编程语言 > 详细

Python 文件操作

时间:2018-12-05 21:45:32      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:内容   open   close   bsp   print   nbsp   连接   操作   coding   

# r:read 只读
f = open("例子.txt", mode = "r", encoding = "utf-8")
# 读取内容
content = f.read() # 全部都读取出来
print(content)

# 坑:
c2 = f.read() #读取不到内容, 因为上面已经读取完毕,光标在末尾
print("c2",c2)

# 良好习惯
f.close() # 关闭连接

  

 

Python 文件操作

标签:内容   open   close   bsp   print   nbsp   连接   操作   coding   

原文地址:https://www.cnblogs.com/demons97/p/10073440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!