Need advice on reading contents of a file into memory

Felipe Almeida Lessa felipe.lessa at gmail.com
Wed Mar 15 22:57:08 CET 2006


Em Qua, 2006-03-15 às 13:49 -0800, vinjvinj escreveu:
> f = open(someFilePath, "rb")
> content = []
> for data in content.read()
>    content.append(data)
> fullContent = "".join(content)
> 
> Is there a more efficient way of doing this? I'll be running this
> operation on 10,000+ files where each file is an image file with size
> 50k-100k

If you really need everything in memory, why not just...

fullContent = open(someFilePath, "rb").read()

...?




More information about the Python-list mailing list