0

I have an django app which create csv file from database queryset and send it to api as following

#create queryset
qs=Apple.objects.filter(args)
#create csv file 
with open('foo.csv','wb') as f:
    write(qs,f)
    res=requests.post(url,{'file':f})

I didnt list full code of creating csv from queryset because it isnt important for me. My focus is on csv file itself. I want to create csv, send it than destroy it. Because neccesity in csv file only that api where i send data receive data only in csv. And data which i put in csv have in my darabase. Currently after sending file i delete it by os.remove but i didnt like it. I was thinking about temporary file or any another solution

3
  • 2
    OK, what's wrong with a temp file? Commented Dec 21, 2020 at 11:22
  • See this post for dealing with temporary files in Python. Commented Dec 21, 2020 at 11:23
  • 3
    You can use an in-memory file using docs.python.org/3/library/io.html#text-i-o Commented Dec 21, 2020 at 11:24

0

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.