Python 基础 读写文件
来源:互联网 发布:win10 软件显示乱码 编辑:程序博客网 时间:2024/06/04 18:02
open 打开文件,当文件不存在时会创建一个空文件
打开后要执行关闭命令,close
text = 'This is my first test.\nThis is next line\nThis is last line.'print(text)my_file = open('my file.txt','w')my_file.write(text)my_file.close()
在打开的文件中追加内容,open的参数为 a
append_text = '\nThis is appended file.my_file = open('my file.txt','a')my_file.write(append_text)my_file.close()
把file里的内容存入content中
file = oprn('myfile.txt','r')content = file.read()print(content)
阅读全文
0 0
- Python文件读写基础
- Python 基础 读写文件
- python基础:读写文件和合并文件
- Python 文件读写基础操作实例
- python基础——文件读写
- python--python读写文件
- python基础-文件读写'r' 和 'rb'区别
- python基础-文件读写'r' 和 'rb'区别
- 文件读写基础
- STL文件读写基础
- STL文件读写基础
- C++基础:文件读写
- Java基础 文件读写
- Python读写Unicode文件
- python Ini文件读写
- Python读写文件
- Python读写文件
- Python读写ini文件
- 浅拷贝和Clone方法
- 水仙花数
- 创建线程的两种方法
- 超级详细 倍增法 实现 LCA
- 数组的一些常见问题
- Python 基础 读写文件
- 经典的java自定义数据库连接池代码
- Jquery Table 的基本操作
- 机器学习中防止过拟合的处理方法
- PAT 1005 Spell It Right
- Android MVVM+DataBinding结合Dagger2进行开发
- Linux学习篇第三章之~samba
- ubuntu正确安装jdk
- 自定义拦截器