所以,我找到了一种对我有效的方法。我有 1.60 GB 的文件,需要加载进行处理。
s3 = boto3.client('s3', aws_access_key_id=<aws_access_key_id>, aws_secret_access_key=<aws_secret_access_key>)
# Now we collected data in the form of bytes array.
data_in_bytes = s3.Object(bucket_name, filename).get()['Body'].read()
#Decode it in 'utf-8' format
decoded_data = data_in_bytes.decode('utf-8')
#I used io module for creating a StringIO object.
stringio_data = io.StringIO(decoded_data)
#Now just read the StringIO obj line by line.
data = stringio_data.readlines()
#Its time to use json module now.
json_data = list(map(json.loads, data))
Run Code Online (Sandbox Code Playgroud)
json_data文件的内容也是如此。我知道有很多变量操作,但它对我有用。
| 归档时间: |
|
| 查看次数: |
8941 次 |
| 最近记录: |