2016-12-31 78 views
5

我是新來的蟒蛇,我試圖寫一個簡單的代碼轉換爲avro文本文件。我得到這個錯誤,找不到該模塊。我可以在schema.py文件中清楚地看到分析模塊存在。如果有人能幫助我理解我可能做錯了什麼,我將不勝感激。模塊'avro.schema'沒有屬性'解析'

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()) 

我使用Python 3.5.2,Avro的-python3-1.8.1在Windows 10

回答

9

你從他們tutorial得到了Avro的代碼示例,但遺憾的是它沒有更新的avro-python3

相反的:

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

您需要閱讀在文本模式下的文件,並使用Parse()方法:

schema = avro.schema.Parse(open('file.avsc', "r").read()) 
相關問題