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

相关推荐
Olamyh21 分钟前
【 超越 ReAct:手搓 Plan-and-Execute (Planner) Agent】
python·ai
deepxuan22 分钟前
Day7--python
开发语言·python
曲幽32 分钟前
FastAPI不止于API:手把手教你用Jinja2打造动态Web页面
python·fastapi·backend·jinja2·full stack·template engine·web development
禹凕37 分钟前
Python编程——进阶知识(多线程)
开发语言·爬虫·python
Ulyanov41 分钟前
基于Pymunk物理引擎的2D坦克对战游戏开发
python·游戏·pygame·pymunk
铉铉这波能秀41 分钟前
LeetCode Hot100数据结构背景知识之字典(Dictionary)Python2026新版
数据结构·python·算法·leetcode·字典·dictionary
程序媛徐师姐1 小时前
Python基于爬虫的网络小说数据分析系统【附源码、文档说明】
爬虫·python·python爬虫·网络小说数据分析系统·pytho网络小说数据分析系统·python爬虫网络小说·python爬虫的网络小说数据
清水白石0081 小时前
深入解析 LRU 缓存:从 `@lru_cache` 到手动实现的完整指南
java·python·spring·缓存
JaydenAI1 小时前
[LangChain之链]LangChain的Chain——由Runnable构建的管道
python·langchain
kali-Myon1 小时前
2025春秋杯网络安全联赛冬季赛-day3
python·安全·web安全·ai·php·web·ctf