withopen("spus.jsonl", encoding="utf8") as fp: for item in jsonlines.Reader(fp): print(item)
openpyxl
读取表格
1 2 3 4 5 6 7
workbook = load_workbook(file_path) sheet = workbook.active # 获取当前工作簿的活动工作表 for row in sheet.iter_rows( values_only=True, # 只返回每行的值 min_row=2# 从第二行开始读,跳过标题 ): data.append(row)
写入表格
1 2 3 4 5
workbook = Workbook() sheet = workbook.active for row in data: sheet.append(row) workbook.save("cxs.xlsx")
单元格颜色
1 2 3 4 5 6 7 8 9 10 11
# 选择单元格 cell = ws['C1'] # 获取填充对象 fill = cell.fill # 检查填充类型 if fill.fill_type == 'solid': # 获取填充颜色 color = fill.start_color print(f"The color of cell A1 is {color.rgb}") else: print("Cell A1 does not have a solid fill color.")
zipfile
解压缩
1 2
with zipfile.ZipFile(zip_file, "r") as zip_ref: zip_ref.extractall(file_path)