Save data to a file thru a http connection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yinglcs@gmail.com

    #1

    Save data to a file thru a http connection

    Hi,

    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.

    Thank you.

  • Christoph Haas

    #2
    Re: Save data to a file thru a http connection

    On Wed, May 31, 2006 at 11:37:47AM -0700, yinglcs@gmail.c om wrote:[color=blue]
    > 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.[/color]

    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.

    Kindly
    Christoph

    Comment

    • Scott David Daniels

      #3
      Re: Save data to a file thru a http connection

      yinglcs@gmail.c om wrote:[color=blue]
      > 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.[/color]

      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
      scott.daniels@a cm.org

      Comment

      • Christoph Haas

        #4
        Re: Save data to a file thru a http connection

        On Wed, May 31, 2006 at 08:58:53PM +0200, Christoph Haas wrote:[color=blue]
        > On Wed, May 31, 2006 at 11:37:47AM -0700, yinglcs@gmail.c om wrote:[color=green]
        > > 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.[/color]
        >
        > 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.[/color]

        Misunderstandin g on my side. Ignore me. :)

        Christoph

        Comment

        • yinglcs@gmail.com

          #5
          Re: Save data to a file thru a http connection

          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

          Scott David Daniels wrote:[color=blue]
          > yinglcs@gmail.c om wrote:[color=green]
          > > 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.[/color]
          >
          > 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
          > scott.daniels@a cm.org[/color]

          Comment

          • John Machin

            #6
            Re: Save data to a file thru a http connection

            On 1/06/2006 11:52 AM, yinglcs@gmail.c om wrote:[color=blue]
            > 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[/color]


            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 :-)

            [color=blue]
            >
            > Scott David Daniels wrote:[color=green]
            >> yinglcs@gmail.c om wrote:[color=darkred]
            >>> 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.[/color]
            >> 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
            >> scott.daniels@a cm.org[/color]
            >[/color]

            Comment

            Working...