How to create temp file in memory???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wenhua Zhao

    #1

    How to create temp file in memory???

    A.T.T

    Thanks a lot.
  • jepler@unpythonic.net

    #2
    Re: How to create temp file in memory???

    Here's how:

    1. open your web browser
    2. visit the url http://docs.python.org
    3. click the link "Library Reference" (keep this under your pillow)
    4. scan down the list of modules until you see these two items:
    4.6 StringIO -- Read and write strings as files
    4.7 cStringIO -- Faster version of StringIO
    5. ?????
    6. profit

    Jeff

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.1 (GNU/Linux)

    iD8DBQFDQ+oGJd0 1MZaTXX0RArg4AJ 440SZ8LdMEakO/KMscH6tDMTLHugC dGJ/C
    72cNpx7bGhixH1w gQIP1QYE=
    =Trj+
    -----END PGP SIGNATURE-----

    Comment

    • Jeremy Jones

      #3
      Re: How to create temp file in memory???

      Wenhua Zhao wrote:
      [color=blue]
      >A.T.T
      >
      >Thanks a lot.
      >
      >[/color]
      If you could elaborate a bit more, it might be helpful. I'm guessing
      you want something like StringIO or cStringIO.


      - jmj

      Comment

      • Wenhua Zhao

        #4
        Re: How to create temp file in memory???

        I have a list of lines. I want to feed these lines into a function.
        The input of this function is a file.
        I want to creat a temp file on disk, and write the list of lines into
        this temp file, then reopen the file and feed it to the function.
        Can I create a this temp file on memory???



        Jeremy Jones wrote:[color=blue]
        > Wenhua Zhao wrote:
        >[color=green]
        >> A.T.T
        >>
        >> Thanks a lot.
        >>
        >>[/color]
        > If you could elaborate a bit more, it might be helpful. I'm guessing
        > you want something like StringIO or cStringIO.
        >
        >
        > - jmj[/color]

        Comment

        • Jeremy Jones

          #5
          Re: How to create temp file in memory???

          Wenhua Zhao wrote:
          [color=blue]
          >I have a list of lines. I want to feed these lines into a function.
          >The input of this function is a file.
          >I want to creat a temp file on disk, and write the list of lines into
          >this temp file, then reopen the file and feed it to the function.
          >Can I create a this temp file on memory???
          >
          >
          >
          >Jeremy Jones wrote:
          >
          >[color=green]
          >>Wenhua Zhao wrote:
          >>
          >>
          >>[color=darkred]
          >>>A.T.T
          >>>
          >>>Thanks a lot.
          >>>
          >>>
          >>>
          >>>[/color]
          >>If you could elaborate a bit more, it might be helpful. I'm guessing
          >>you want something like StringIO or cStringIO.
          >>
          >>
          >>- jmj
          >>
          >>[/color][/color]
          If the function takes a file object as an argument, you should be able
          to use StringIO or cStringIO.


          - jmj

          Comment

          • Diez B. Roggisch

            #6
            Re: How to create temp file in memory???

            Wenhua Zhao wrote:[color=blue]
            > I have a list of lines. I want to feed these lines into a function.
            > The input of this function is a file.
            > I want to creat a temp file on disk, and write the list of lines into
            > this temp file, then reopen the file and feed it to the function.
            > Can I create a this temp file on memory???[/color]

            Yes, the answer has been given to yoou already: (c?)StringIO will help you.

            Diez

            Comment

            Working...