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

相关推荐
陈苏同学38 分钟前
MPC控制器从入门到进阶(小车动态避障变道仿真 - Python)
人工智能·python·机器学习·数学建模·机器人·自动驾驶
mahuifa42 分钟前
python实现usb热插拔检测(linux)
linux·服务器·python
MyhEhud1 小时前
kotlin @JvmStatic注解的作用和使用场景
开发语言·python·kotlin
狐凄1 小时前
Python实例题:pygame开发打飞机游戏
python·游戏·pygame
漫谈网络2 小时前
Telnet 类图解析
python·自动化·netdevops·telnetlib·网络自动化运维
农夫山泉2号3 小时前
【python】—conda新建python3.11的环境报错
python·conda·python3.11
ZHOU_WUYI4 小时前
Flask Docker Demo 项目指南
python·docker·flask
码上淘金8 小时前
【Python】Python常用控制结构详解:条件判断、遍历与循环控制
开发语言·python
Brilliant Nemo8 小时前
四、SpringMVC实战:构建高效表述层框架
开发语言·python
2301_787552879 小时前
console-chat-gpt开源程序是用于 AI Chat API 的 Python CLI
人工智能·python·gpt·开源·自动化