Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52025
| Date | 2013-08-06 06:40 -0400 |
|---|---|
| From | Devyn Collier Johnson <devyncjohnson@gmail.com> |
| Subject | Re: Sort lines in a plain text file alphanumerically |
| References | <520058D7.10105@Gmail.com> <mailman.228.1375758799.1251.python-list@python.org> <ktprbs$lpf$1@dont-email.me> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.240.1375785609.1251.python-list@python.org> (permalink) |
On 08/05/2013 11:49 PM, alex23 wrote:
> 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.
I tried Joshua's suggestion in Python3.3 and it worked. What version of
Python are you using?
DCJ
Back to comp.lang.python | Previous | Next — Previous 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