Need advice on reading contents of a file into memory
Fredrik Lundh
fredrik at pythonware.com
Wed Mar 15 17:02:00 EST 2006
"vinjvinj" wrote:
> 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?
read reads until end of file, so unless the source is something unusual,
a plain
fullContent = content.read()
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)
</F>
More information about the Python-list
mailing list