lwaekfjlk's picture
Upload Time-Series-Library
f9d3aeb verified
import json
def load_first_jsonl_record(filepath):
try:
with open(filepath, 'r', encoding='utf-8') as f:
first_line = f.readline().strip()
if first_line:
return json.loads(first_line)
else:
print("文件为空")
return None
except FileNotFoundError:
print(f"文件未找到: {filepath}")
return None
except json.JSONDecodeError as e:
print(f"JSON解析错误: {e}")
return None
except Exception as e:
print(f"发生错误: {e}")
return None
# 使用示例
if __name__ == "__main__":
filepath = "/data/haofeiy2/social-world-model/data/splitted_polymarket/polymarket_data_processed_with_news_train_2024-11-01.jsonl"
first_record = load_first_jsonl_record(filepath)
breakpoint()
if first_record:
print("第一条记录:")
print(json.dumps(first_record, ensure_ascii=False, indent=2))