Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51997
| From | alex23 <wuwei23@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Sort lines in a plain text file alphanumerically |
| Date | 2013-08-06 13:49 +1000 |
| Organization | A noiseless patient Spider |
| Message-ID | <ktprbs$lpf$1@dont-email.me> (permalink) |
| References | <520058D7.10105@Gmail.com> <mailman.228.1375758799.1251.python-list@python.org> |
On 6/08/2013 1:12 PM, Joshua Landau wrote:
> Because it's bad to open files without a with unless you know what
> you're doing, use a with:
>
> with open('/home/collier/pytest/__sort.TXT') as file:
> sorted(file, key=str.casefold, reverse=True)
Shouldn't that be:
with open('/home/collier/pytest/__sort.TXT') as file:
data = file.readlines()
sorted(data, key=str.casefold, reverse=True)
I'm tempted to say "HINT #5: don't provide a solution without testing it
first" but that would be pretty obnoxious.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Sort lines in a plain text file alphanumerically Joshua Landau <joshua@landau.ws> - 2013-08-06 04:12 +0100
Re: Sort lines in a plain text file alphanumerically alex23 <wuwei23@gmail.com> - 2013-08-06 13:49 +1000
Re: Sort lines in a plain text file alphanumerically alex23 <wuwei23@gmail.com> - 2013-08-06 13:51 +1000
Re: Sort lines in a plain text file alphanumerically alex23 <wuwei23@gmail.com> - 2013-08-06 14:33 +1000
Re: Sort lines in a plain text file alphanumerically Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-08-06 06:40 -0400
csiph-web