我已將 AVRO 文件(帶有 JSON 負(fù)載)從 Microsoft Azure 下載到我的 Windows 10 計(jì)算機(jī):然后通過(guò) pip 安裝 python 3.8.5 和 avro 1.10.0 我嘗試運(yùn)行以下腳本:import os, avrofrom avro.datafile import DataFileReader, DataFileWriterfrom avro.io import DatumReader, DatumWriterreader = DataFileReader(open("48.avro", "rb"), DatumReader())for d in reader: print(d)reader.close()不幸的是,腳本沒(méi)有打印任何內(nèi)容。然后我四處搜索并嘗試添加如下所示的架構(gòu):schema_str = """{ "type" : "record", "name" : "EventData", "namespace" : "Microsoft.ServiceBus.Messaging", "fields" : [ { "name" : "SequenceNumber", "type" : "long" }, { "name" : "Offset", "type" : "string" }, { "name" : "EnqueuedTimeUtc", "type" : "string" }, { "name" : "SystemProperties", "type" : { "type" : "map", "values" : [ "long", "double", "string", "bytes" ] } }, { "name" : "Properties", "type" : { "type" : "map", "values" : [ "long", "double", "string", "bytes", "null" ] } }, { "name" : "Body", "type" : [ "null", "bytes" ] } ]}"""schema = avro.schema.parse(schema_str)reader = DataFileReader(open("48.avro", "rb"), DatumReader(schema, schema))for d in reader: print(d)reader.close()但這并沒(méi)有幫助,仍然沒(méi)有打印任何內(nèi)容。雖然我期待會(huì)打印字典對(duì)象列表......
如何在Windows 10上使用avro-python3解析文件?
墨色風(fēng)雨
2023-09-19 13:59:26