in-memory-only file object from string

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

    #1

    in-memory-only file object from string

    Hello,

    how to create a file object whose contents I initialize from a string
    and which is purely in memory?
    I can make a workaround like this:

    filecontents = "Very interesting stuff ... "
    file = os.tmpfile ()
    file.write (filecontents)
    file.seek (0)
    procedure (fileobject = file)

    but this creates a file on harddisk. Instead I would like to use
    something like:

    filecontents = "Very interesting stuff ... "
    file = stringfile (filecontents)
    procedure (fileobject = file)

    Is this possible somehow? I appreciate any help.

  • Gabriel Genellina

    #2
    Re: in-memory-only file object from string

    At Wednesday 23/8/2006 18:56, bobrik wrote:
    >how to create a file object whose contents I initialize from a string
    >and which is purely in memory?
    See the standard modules: StringIO and cStringIO



    Gabriel Genellina
    Softlab SRL





    _______________ _______________ _______________ _____
    Preguntá. Respondé. Descubrí.
    Todo lo que querías saber, y lo que ni imaginabas,
    está en Yahoo! Respuestas (Beta).
    ¡Probalo ya!


    Comment

    • bobrik

      #3
      Re: in-memory-only file object from string

      See the standard modules: StringIO and cStringIO
      Thank you!

      Comment

      Working...