🚀 作者 :“码上有前”
🚀 文章简介 :Python
🚀 欢迎小伙伴们 点赞👍、收藏⭐、留言💬
python练习题
读取文件夹下所有的csv文件
def search_store_prices(folder_path, store_list):
store_prices = {
}
# 遍历文件夹下的所有文件
for filename in os.listdir(folder_path):
if filename.endswith(".csv"):
file_path = os.path.join(folder_path, filename)
# 打开 CSV 文件
with open(file_path, 'r', encoding='utf-8') as file:
csv_reader = csv.DictReader(file)
# 遍历 CSV 文件的每一行
for row in csv_reader:
store_name = row.get('店铺')
price = row.get('\ufeff价格')
# 检查店铺名是否在给定的店铺列表中
if store_name in store_list:
# 将店铺名和价格添加到结果字典中
if store_name not in store_prices: