data = s3client.get_object(Bucket='', Key='')
data1 = data['Body']
data2 = json.load(data1)
data2 = json_normalize(data=data2)
data2 = sor.explode('header.head')
data2 = data2.to_dict('records')
data2 = json_normalize(data2)
我正在使用上面的json文件代码取消嵌套复杂的json和分析数据。如何执行相同的操作来流文本文件并查看内容。
data = s3client.get_object(Bucket='', Key='')
data1 = data['Body']
with open(data1) as sample:
for line in sample:
print(line.rstrip())
我遇到以下错误
TypeError: expected str, bytes or os.PathLike object, not StreamingBody
答案 0 :(得分:1)
通常,您将使用iter_lines或iter_chunks。例如:
data = s3client.get_object(Bucket='', Key='')
for line in data['Body'].iter_lines():
print(line)
请注意,line
将是bytes
,而不是str
。