读到结束文件后,你需要用结束文件里的批号在开始数据库里面检索同批号那一条数据,然后把它捞出来。怎么写
时间: 2023-05-12 11:05:40 浏览: 41
您可以使用以下代码来实现这个功能:
```python
import csv
def search_batch_number(batch_number, start_database_file, end_database_file):
# 读取结束文件
with open(end_database_file, 'r') as end_file:
end_reader = csv.reader(end_file)
# 获取结束文件中同批号的数据
for row in end_reader:
if row[0] == batch_number:
end_data = row
break
# 读取开始文件
with open(start_database_file, 'r') as start_file:
start_reader = csv.reader(start_file)
# 获取开始文件中同批号的数据
for row in start_reader:
if row[0] == batch_number:
start_data = row
break
# 返回同批号的数据
return start_data, end_data
```
这个函数接受三个参数:批号、开始数据库文件名和结束数据库文件名。它会先读取结束文件,找到同批号的数据,然后再读取开始文件,找到同批号的数据,并返回这两条数据。您可以根据需要对返回的数据进行处理。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![bat](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![csv](https://img-home.csdnimg.cn/images/20210720083646.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![exe](https://img-home.csdnimg.cn/images/20210720083343.png)