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")
相关推荐
代码不停13 小时前
Redis基本数据类型
数据库·redis
2401_8685347813 小时前
55 个热门网络面试问题及答案
网络·python
用户693717500138413 小时前
大模型蒸馏到底在蒸什么?一篇文章搞懂知识蒸馏概念
前端·后端·github
aifannihao13 小时前
ON CONFLICT 冲突后返回空:sqlite3 实测 get-or-create
数据库·python·postgresql·sqlite3·标准库
徐小夕13 小时前
实测 10 个前端 UI 生成开源 Skill|AI 输出直达上线标准
前端·vue.js·github
tong_li13 小时前
给娃做个 AI 陪写作业助手:LangChain4j 入门(八):AI 知道这字哪课学的(SQLite 结构化查询入门)
前端·langchain
用户03321266636714 小时前
使用 Python 合并 Excel 工作簿
python
__underline__14 小时前
冷门Python知识点008篇:__int__、__index__与__float__,Python数值转换的真实回退顺序?
后端·python
得物技术14 小时前
Computer Use与Browser Use:揭秘Agent如何操作电脑和浏览器|得物技术
数据库·github·ai编程
小小程序员.¥14 小时前
mysql备份以及数据恢复实战
数据库·mysql