Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63911
| Date | 2014-01-14 08:18 -0600 |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Subject | Re: Python Fast I/o |
| References | <a9c545f2-fbc3-4ac4-81ee-a91f61c72b84@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5462.1389712154.18130.python-list@python.org> (permalink) |
On 2014-01-14 05:50, Ayushi Dalmia 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()
>
> where data is a list of strings which I want to dump into the
> index.txt file --
Most file-like objects should support a writelines() method which
takes an iterable and should save you the trouble of joining all the
content (and as Chris noted, you don't need the .close() since the
with handles it) so the whole thing would condense to:
with open('index.txt', 'w') as f:
f.writelines(data)
-tkc
Back to comp.lang.python | Previous | Next — Previous 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