How much memory used by a name
Fredrik Lundh
fredrik at pythonware.com
Thu Feb 15 07:47:17 EST 2007
Bernard Lebel wrote:
> Bruno: good question. We're talking about text files that can have
> 300,000 lines, if not more. Currently, the way I have coded the file
> writing, every line calls for a write() to the file object, which in
> turns write to the text file. The file is on the network.
assuming an average line length of 30 (for program code) to 60-80
characters (for human text), that's no more than 12-24 megabytes of
data. few modern computers should have any trouble holding that in
memory.
just build the list in memory, and use a single "writelines" call to write
everything to disk.
(alternatively, try write("".join(data)). that'll use twice as much memory,
but may be a little bit faster)
> This is taking a long time, and I'm looking for ways to speed up this
> process. I though that keeping the list in memory and dropping to the
> file at the very end could be a possible approach.
chances are that you're already I/O bound, though...
</F>
More information about the Python-list
mailing list