我正在使用CSVRecordSource读取Apache Beam管道中的CSV文件,该管道在read_records函数中使用open_file。Python 2一切正常,但当我迁移到Python 3时,它会抱怨以下问题。
默认情况下,open_file方法会使用二进制模式打开文件。
所以我将其更改为使用:
next(csv_reader)
_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
默认情况下,open_file方法会使用二进制模式打开文件。
所以我将其更改为使用:
with open(filename, "rt") as f:
但是当我在Google云中运行数据流时,它找不到文件并报错。
FileNotFoundError: [Errno 2] No such file or directory
以下是我的代码
with self.open_file(filename) as f:
csv_reader = csv.reader(f, delimiter=self.delimiter, quotechar=self.quote_character)
header = next(csv_reader)
我该如何在python 3中使用CSVRecordSource?