from plyfile import PlyData

# ply = PlyData.read('3dgs_test.ply')
# vertex = ply['vertex'].data
#
# print("所有字段名:")
# print(vertex.dtype.names)
# print("\n前5行数据（每行为dict可索引）:")
# for i in range(5):
#     print({k: vertex[k][i] for k in vertex.dtype.names})




header_lines = []
with open('3dgs_test.ply', 'rb') as f:
    while True:
        line = f.readline()
        # 解码header行（防止错误，可用latin1等宽容模式）
        try:
            line_str = line.decode('utf-8').strip()
        except UnicodeDecodeError:
            line_str = line.decode('latin1').strip()
        header_lines.append(line_str)
        if line_str == "end_header":
            break
# 打印所有header
for l in header_lines:
    print(l)