[Tutor] Load Entire File into memory

Alan Gauld alan.gauld at btinternet.com
Mon Nov 4 12:35:34 CET 2013


On 04/11/13 11:07, Amal Thomas wrote:

>    I am currently using this method to load my text file:
> *f = open("output.txt")
> content=io.StringIO(f.read())
> f.close()*
>   But I have found that this method uses 4 times the size of text file.

So why not use

f = open("output.txt")
content=f.read()
f.close()

And process the file as a raw string?

Is there a reason for using the StringIO?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list