Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63905
| References | <a9c545f2-fbc3-4ac4-81ee-a91f61c72b84@googlegroups.com> |
|---|---|
| Date | 2014-01-15 01:03 +1100 |
| Subject | Re: Python Fast I/o |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5458.1389708197.18130.python-list@python.org> (permalink) |
On Wed, Jan 15, 2014 at 12:50 AM, Ayushi Dalmia
<ayushidalmia2604@gmail.com> wrote:
> I need to write into a file for a project which will be evaluated on the basis of time. What is the fastest way to write 200 Mb of data, accumulated as a list into a file.
>
> Presently I am using this:
>
> with open('index.txt','w') as f:
> f.write("".join(data))
> f.close()
with open('index.txt','w') as f:
for hunk in data:
f.write(hunk)
You don't need to f.close() - that's what the 'with' block guarantees.
Iterating over data and writing each block separately means you don't
have to first build up a 200MB string. After that, your performance is
going to be mainly tied to the speed of your disk, not anything that
Python can affect.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python Fast I/o Ayushi Dalmia <ayushidalmia2604@gmail.com> - 2014-01-14 05:50 -0800
Re: Python Fast I/o Chris Angelico <rosuav@gmail.com> - 2014-01-15 01:03 +1100
Re: Python Fast I/o Ayushi Dalmia <ayushidalmia2604@gmail.com> - 2014-01-14 06:24 -0800
Re: Python Fast I/o Chris Angelico <rosuav@gmail.com> - 2014-01-15 01:32 +1100
Re: Python Fast I/o Roy Smith <roy@panix.com> - 2014-01-14 09:40 -0500
Re: Python Fast I/o Tim Chase <python.list@tim.thechases.com> - 2014-01-14 08:18 -0600
csiph-web