简体   繁体   中英

module 'avro.schema' has no attribute 'parse'

i am new to python and i was trying to write a simple code for converting a text file to avro. i am getting this error that module not found. I could clearly see in the schema.py file that the parse module exists. I will appreciate if someone could help me understand what i may be doing wrong.

import avro.schema, csv, codecs
from avro.datafile import DataFileReader, DataFileWriter
from avro.io import DatumReader, DatumWriter


def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs):
# csv.py doesn't do Unicode; encode temporarily as UTF-8:
csv_reader = csv.reader(utf_8_encoder(unicode_csv_data),
                        dialect=dialect, **kwargs)
for row in csv_reader:
    # decode UTF-8 back to Unicode, cell by cell:
    yield [unicode(cell, 'utf-8') for cell in row]

def utf_8_encoder(unicode_csv_data):
for line in unicode_csv_data:
    yield line.encode('utf-8')

schema = avro.schema.parse(open('C:/test/test.avsc', "rb").read())

I am using Python 3.5.2, avro-python3-1.8.1 on Windows 10.

You got the avro code sample from their tutorial , but unfortunately it's not updated for avro-python3 .

Instead of:

schema = avro.schema.parse(open('file.avsc', "rb").read())

You need to read the file in text mode, and use the Parse() method:

schema = avro.schema.Parse(open('file.avsc', "r").read())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM