Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52025

Re: Sort lines in a plain text file alphanumerically

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <devyncjohnson@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'subject:text': 0.05; 'subject:file': 0.07; 'subject:skip:a 10': 0.09; 'worked.': 0.09; 'python': 0.11; 'be:': 0.16; 'doing,': 0.16; 'subject:Sort': 0.16; 'tempted': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; "shouldn't": 0.24; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'testing': 0.29; "i'm": 0.30; 'received:10.0.0': 0.31; 'file:': 0.31; 'open': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'received:10.0': 0.36; 'received:10': 0.37; 'to:addr:python-list': 0.38; 'files': 0.38; 'pm,': 0.38; 'bad': 0.39; 'to:addr:python.org': 0.39; 'skip:o 30': 0.61; "you're": 0.61; 'provide': 0.64
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=9S/GhescerGX46aRrxn9rWuKmdg1miVMmlAKfj2Nyfs=; b=WMeISy92GKgKSNF+chl+NZdfLoVvpRCBqjzgsvC7u1KdUY12UftR74l2HglWfqCTG7 tZel7b2E+9BZ6pWSIP3AUhS4UpnFnH0SZvmFtKMxvbukANHsYUUBltASDewKUzitGjLk T2ZLwkPmhtqbJaVKFSe+jsWb/EumQ/xHE7ZO8ttVF/wG1yyUYVTKnFKYONUYuKbYZRcg 01QODKfyERqcMJUF9FeUO8oTcPi0+fUXp8xXeuZuQdkLFUUskjcWqPdQOLkHw66pvHK7 lB2DVqEVUCYTLIPHPKQBWLvlJ31+Irmqiw3+IbGG7whv9uwlaQUchvqAGFvgWSq9gPvf jDcw==
X-Received by 10.182.199.74 with SMTP id ji10mr449654obc.69.1375785606293; Tue, 06 Aug 2013 03:40:06 -0700 (PDT)
Date Tue, 06 Aug 2013 06:40:03 -0400
From Devyn Collier Johnson <devyncjohnson@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130803 Thunderbird/17.0.8
MIME-Version 1.0
To Python Mailing List <python-list@python.org>
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>
In-Reply-To <ktprbs$lpf$1@dont-email.me>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.240.1375785609.1251.python-list@python.org> (permalink)
Lines 21
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1375785609 news.xs4all.nl 15873 [2001:888:2000:d::a6]:54435
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52025

Show key headers only | View raw


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 | NextPrevious in thread | Find similar | Unroll thread


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