python - 在 Python 中从文件中的两个匹配项之间提取数据
问题描述
Table 1 Qualitative composition of SERQUEL 25 mg tablets
Ingredient Function Reference to standards
Tablet core
Quetiapine fumarate Drug substance This document
Povidone Binder USP
Dibasic calcium phosphate dihydrate Diluent USP
Microcrystalline cellulose Diluent USNF
Sodium starch glycolate Disintegrant USNF
Lactose monohydrate Diluent USNF
Magnesium stearate Lubricant USNF
Purified water Granulating vehicle USP
以上表示来自 .txt 文件的示例数据:
我有一个要匹配的物质名称列表。(csv 文件中的物质示例是否'Quetiapine fumarate', 'Povidone', 'Magnesium stearate' etc etc.)
存在于 csv 文件中。我想迭代文本文件的每一行并创建从一种物质到另一种物质的组. 示例输出:
['Quetiapine fumarate Drug substance This document'],
['Povidone Binder USP'],
['Lactose monohydrate Diluent USNF'],
['Magnesium stearate Lubricant USNF']
鉴于“富马酸喹硫平”、“聚维酮”、“乳糖一水合物”、“硬脂酸镁”存在于我的 csv 物质列表中。
我如何在 Python 中做到这一点
解决方案
您可以使用 readlines 命令
file = open(FOLDER_NAME + '/' + name, 'r', encoding='utf-8')
data = file.readlines()
for line in data:
words=line.split()
print(words)
您可以搜索“从python中的文件中读取”
推荐阅读
- javascript - 反应滚动上一个视图内容
- android - Android 10:cordova-plugin-mfilechose 不工作
- c# - 确定字符串是否在文本内容内或属性的一部分
- c - 将字符串存储在二进制文件中,同时保持它们按字母顺序排序
- snakemake - 从 csv 定义输入文件
- javascript - 打字稿中的动态导入在测试或 webpack 运行时被破坏
- javascript - Google Analytics 获取自定义报告
- excel - 如何在 Matlab 中使用泊松分布进行计算?
- javascript - 将多个键匹配到单个值的最简洁方法?
- mongodb - MongoDB - 将字符串数组与二维数组合并