Reputation: 41
I have a file named data.dat
in an S3 bucket, the contents of the file are in 3 lines
fruit javaisnotafruit xyq
I am reading from s3 this way
objectcontent = s3.get_object(Bucket="contents-bucket", Key=obj['Key'])
contentsins3 = objectcontent['Body'].read().decode('utf-8')
print(contentsins3)
When I do print(contentsins3)
I am getting
fruit javaisnotafruit xyq
I have code for looping through the contents and read each line, how would I do that?
for i in contentsins3:
print(i)
How would I get each line in S3 line by line?
Upvotes: 1
Views: 1125
Reputation: 13166
This is just plain string parsing, regardless of the storage.
So back to python, the object contentsins3
contains the whole file data, together with the line break
.
You can use splitlines() which will deal with \n
, \r\n
.
for i in contentsins3.splitlines():
print(i)
Upvotes: 0