Python基础学习-09文件操作

目录

1、常见文件操作

2、常见文件函数

3、文件中存储并解析Python对象

4、本节总结


1、常见文件操作

• 常见文件操作

1) file=open(file_path) #默认mode=rt

2) file=open(file_path, "r+")

3) file=open(file_path, encoding="utf-8")

• mode参数

1) r、 w、 x、 a

2) b、 t

3) +

2、常见文件函数

1) file.read()、 file.read(N)、 file.readline()、 file.readlines()

2) file.write()、 file.write(str)、 file.writelines(strList)

3) file.close()、 file.flush()

4) file.tell()、 file.seek(N)

5) name、 encoding

3、文件中存储并解析Python对象

1)字符串要去掉换行

2) eval()函数将字符串内容转成对应的python对象

4、本节总结

• 如何掌握本节内容

1)文件的操作、函数等

2)课后:把代码自己敲一遍

相关推荐
ZhengEnCi20 小时前
M3-markconv库找不到wkhtmltopdf问题
python
2301_764441331 天前
LISA时空跃迁分析,地理时空分析
数据结构·python·算法
chushiyunen1 天前
python rest请求、requests
开发语言·python
cTz6FE7gA1 天前
Python异步编程:从协程到Asyncio的底层揭秘
python
baidu_huihui1 天前
在 CentOS 9 上安装 pip(Python 的包管理工具)
开发语言·python·pip
南 阳1 天前
Python从入门到精通day63
开发语言·python
lbb 小魔仙1 天前
Python_RAG知识库问答系统实战指南
开发语言·python
FreakStudio1 天前
MicroPython LVGL基础知识和概念:底层渲染与性能优化
python·单片机·嵌入式·电子diy
素玥1 天前
实训5 python连接mysql数据库
数据库·python·mysql