# 写方法1
f = open('tmp.txt','w')
f.write('hello world')
f.close() # 写方法2
with open('tmp.txt','w') as f:
f.write('hello \n word') # 读
with open('tmp.txt', 'r') as f:
print(f.read()) # 逐行读
with open('tmp.txt','r') as f:
for line in f.readlines():
print(line.strip())#strip()去除空行
相关文章
- ubuntu下的数据库和python存储库安装——MySQL,MongoDB,Redis
- 【头歌】——数据分析与实践-python-Pandas 初体验-Pandas数据取值与选择-Pandas进阶
- 利用Python进行数据分析--数据聚合与分组运算1
- 中标麒麟(linux)下Qt调用python数据转换
- 用java实现从文本文件批量导入数据至数据库
- EasyExcel技术读写excel表格数据,以树形式数据返回前端(springboot)
- Python3-unittest测试框架之DDT数据驱动
- python3 json数据格式的转换(dumps/loads的使用、dict to str/str to dict、json字符串/字典的相互转换)
- 如何优雅地用python生成模拟数据
- 解决python画图坐标轴数据太密集的问题(显示部分刻度值)