473,320 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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/

Jul 18 '05 #1
1 2159
an**@post.tau.ac.il wrote:
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.


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(buf)
print buf

However, file.readinto() has a frightening docstring:
print file.readinto.__doc__ readinto() -> Undocumented. Don't use this; it may go away.


Peter
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Andrew Morgan | last post by:
Hi I have a matrix class: template<class Type> class TMatrix { //... TMatrix& T(); //... }
3
by: news | last post by:
I'm working with a CGI program that was using several standard buttons for input using <input type="submit" name="abuttonName" ... Now, I'm trying to replace the standard buttons with images...
1
by: success_ny | last post by:
I would like to be able to display either one or the other HTML table in the same place. I.e., there are 2 buttons on the screen. When the user clicks one button, the table A is displayed below....
13
by: tshad | last post by:
I have some nested DataGrids in my Datalist. There could be 20 datalist items. If I scroll down to the 18th item and expand it to show the DataGrid, the page always goes back to the beginning...
10
by: Mike Logan | last post by:
I am using the "contract first" design methodology. Contract First is design the WSDL first then design the server and client. However I must design my XSD/XML Schema before anything. I am...
5
by: tlyczko | last post by:
Hello, I've searched on toggling divs and didn't really find what I was looking for, I saved a bunch of different threads. I have a form with several different text boxes for things like dates,...
2
by: peter.mcclymont | last post by:
What is an in-place function? And I guess if that is answered it will be easy to work out what a non-in-place string is. What is the standard way to write a 'library function', e.g. one that...
1
by: peter.mcclymont | last post by:
Hi There, Can you please help me write an in-place function in C++ for reversing a string. What is an in-place function? So what is a non-in-place function in that case to reverse a C++...
15
by: rajash | last post by:
Thanks for the additional comments. Here is a solution to an exercise I had problems with. I still don't think it's really what's wanted as it uses a "state variable" n - but I can't see how to...
3
by: teneesh | last post by:
Hi, I'm trying to find some records in a table that has been exported into Access (tbl_test). The new table that I am trying to create and insert the data to is called (tbl_test1). Here's my...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.