Need advice on reading contents of a file into memory

Fredrik Lundh fredrik at
Wed Mar 15 23:02:00 CET 2006

"vinjvinj" wrote:

> f = open(someFilePath, "rb")
> content = []
> for data in
>    content.append(data)
> fullContent = "".join(content)
> Is there a more efficient way of doing this?

read reads until end of file, so unless the source is something unusual,
a plain

    fullContent =

should be good enough (not that it matters much; that join will be in
no-op, and the list/append overhead is marginal compared to the time
required to get the data from disk)


More information about the Python-list mailing list