in place input

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • andy@post.tau.ac.il

    in place input

    i'm working on an python application with intensive i/o.

    file.read() and its cousins all allocate and return a new string.

    I want to know if there is a way in which I can provide the space on which the
    data is going to be put, in order to recycle memory, instead of allocating it
    each time again and again.

    thanks





    -------------------------------------------------
    This mail sent through IMP: http://horde.org/imp/

  • Peter Otten

    #2
    Re: in place input

    andy@post.tau.a c.il wrote:
    [color=blue]
    > i'm working on an python application with intensive i/o.
    >
    > file.read() and its cousins all allocate and return a new string.
    >
    > I want to know if there is a way in which I can provide the space on which
    > the data is going to be put, in order to recycle memory, instead of
    > allocating it each time again and again.[/color]

    The following may do:

    import array
    file("tmp.txt", "w").write( "x" * 5)
    buf = array.array("c" )
    buf.fromstring( "-" * 10)
    print buf
    file("tmp.txt", "r").readinto(b uf)
    print buf

    However, file.readinto() has a frightening docstring:
    [color=blue][color=green][color=darkred]
    >>> print file.readinto._ _doc__[/color][/color][/color]
    readinto() -> Undocumented. Don't use this; it may go away.[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

    Peter

    Comment

    Working...