0

My requirement is to generate csv file and append to a file in Amazon S3. I am able to do it using loop. My code is something like this.

import csv
import random
import simples3
from  simples3 import S3Bucket


quantity=['12','5','13','2','7','6','4','9','15','21','33','62','54','18','26','1']
unitPrice=['1$','2$','3$','4$','5$','6$','7$','8$','9$','10$']



loop= [10]

myfile = open('testcsv.csv', 'ab')
s = S3Bucket('bucket_name',access_key='access_key',secret_key='secret_key')

for a in range(10):

    writing=(random.choice(quantity),random.choice(unitPrice))
    wr =csv.writer(myfile)
    wr.writerow(writing)

    loop.append(writing)    

myfile.close()
print loop
pls = str(loop)
s.put("testconnection.csv",pls,mimetype="text/plain")

Now i want to write to the bucket file within my loop as i did for file in my local file system. I am not getting enough method in S3Bucket to append to a file and put is overwriting the content of file each time the loop executes. Please help me, i am newbie in Python and Amazon S3 world. Thanks in advance.

1 Answer 1

1

It's not possible to append to existing S3 object. You will have to upload the entire content and replace the old object.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Roger for your answer. I will wait for sometime and see if anyone suggest any work around for this. Else i will accept your answer.
I have accepted this answer because i myself not sure whether we can do it or not. Anyone please let me know if it is possible. Thankyou.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.