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)课后:把代码自己敲一遍

相关推荐
岁月宁静2 小时前
五、《从零手撸 Agent》 — 什么是 Agent:从“会聊天”到“会做事”,差的就是一个循环
python·agent
梯度下降者3 小时前
Python - 函数
python·高阶函数·可调用对象·functools·嵌套作用域
starzy19905 小时前
深入理解Scala隐式参数:上下文流转
开发语言·python·scala
wuyk5556 小时前
Spider-第16讲-线程池与竞态问题
大数据·爬虫·python·elasticsearch·搜索引擎
kyle~12 小时前
FastAPI --- 将业务能力以 API 的形式提供给外部系统
python·fastapi·前后端
aiotto资源分享12 小时前
Python 写 JSON 文件,程序中途退出会留下什么?
java·python·json·jsondecodeerror
梯度下降者13 小时前
Python信号量,条件变量,事件学习
python·条件变量·事件·信号量·线程通信
MSTcheng.14 小时前
【AI应用实战】用 FastAPI + SSE 做一个自己的 AI 聊天网页:流式输出、多轮对话与完整源码
人工智能·python·大模型·fastapi·sse·ai聊天助手
the局外人14 小时前
Python 实战检索优化:BM25、向量与重排
数据库·后端·python
__underline__14 小时前
冷门Python知识点006篇:Python 类体里的名字,能被"凭空造出来"
后端·python