Python:读写操作

一、读写txt

模式:

rawx 【读、加写(add 无则创建)、覆盖写、新创建写(无则报错)】 +bt【可以和上面四个组合使用,分别代表'读写都行'、'二进制'、'文本模式'】

python 复制代码
with open('药品数据.txt','r',encoding='utf-8') as f:
    reads = f.readlines()
    for i in reads:
        data=i.strip().split()
        print(data)
cs 复制代码
with open('药品数据.txt', 'w', encoding='utf-8') as f:
    f.write("这是要写入的字符串\n")
相关推荐
知行合一。。。36 分钟前
Python--04--数据容器(总结)
开发语言·python
架构师老Y40 分钟前
008、容器化部署:Docker与Python应用打包
python·容器·架构
lifewange1 小时前
pytest-类中测试方法、多文件批量执行
开发语言·python·pytest
等....1 小时前
Minio使用
数据库
GreenTea1 小时前
一文搞懂Harness Engineering与Meta-Harness
前端·人工智能·后端
pluvium271 小时前
记对 xonsh shell 的使用, 脚本编写, 迁移及调优
linux·python·shell·xonsh
2401_827499992 小时前
python项目实战09-AI智能伴侣(ai_partner_5-6)
开发语言·python
PD我是你的真爱粉2 小时前
MCP 协议详解:从架构、工作流到 Python 技术栈落地
开发语言·python·架构
ZhengEnCi2 小时前
P2G-Python字符串方法完全指南-split、join、strip、replace的Python编程利器
python
是小蟹呀^2 小时前
【总结】LangChain中工具的使用
python·langchain·agent·tool