Save data to a file thru a http connection

S

Scott David Daniels

I am new to python. I read an example here about how to fetch data thru
a HTTP connection:
http://diveintopython.org/http_web_services/review.html,

My question is how can i save the data to a file after reading it from
a http connection.

Do the tutorial and this and many other things will become clear.

Instead of just "print sometext", do something like:
...
f = open('filename', 'w')
...
print >>f, sometext
... (possibly more prints like the above).
f.close()

--Scott David Daniels
(e-mail address removed)
 
C

Christoph Haas

Usually HTTP is read-only. There are extensions like WebDAV though that
may do what you need. Google for "python webdav" and see how far you get.

Misunderstanding on my side. Ignore me. :)

Christoph
 
J

John Machin

Scott,

Can you please tell me which chapter of the tutorial that you are
referring to http://docs.python.org/tut/tut.html?

The only chapter that I find about http is chapter 10.7, but it does
not have the example that you are referring to


Break the problem up into two parts:

(1) Get some data.

You've achieved that, using HTTP.

(2) Save some data to a file.

Doesn't matter *how* you got the data. You need to know how to open a
file for writing and how to write to it and how to close it when you've
finished. Look for the section in the tutorial about *files*.

Better still, read *all* the sections in the tutorial :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top