Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.049 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'subject:text': 0.05; 'subject:file': 0.07; 'collier': 0.09; 'subject:skip:a 10': 0.09; '"with"': 0.16; 'called.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:Sort': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'aug': 0.22; 'gets': 0.27; 'header:In-Reply- To:1': 0.27; 'point': 0.28; 'chris': 0.29; 'am,': 0.29; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'file:': 0.31; 'stuff': 0.32; 'open': 0.33; 'not.': 0.33; 'advice': 0.35; 'johnson': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'thanks': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'how': 0.40; 'august': 0.61; 'skip:o 30': 0.61; 'tips': 0.61; 'entire': 0.61; 'close': 0.67; 'useful.': 0.68; "'with'": 0.84; 'involved.': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=bcgzM4Bl8Ia+PK+02KhZR3Y9D5oKOyOuog11I/WNSGA=; b=ii0VLSkp+yKwPSIBlYoPL/uPJI8bTAlRh9m46QHuLAVwhfnIvv3kL0d9JDMwZH5rqS U6VClGNIOmyPbY19TlgRadbdvsSGNKhys2pujCEJ6IwugrnWDVl2n7Qm/JAi8kEYKoxA mg/vzgPUkxM51UYdFbGfP3ahGJauXW4/A1b+dFgbLxBRJswKYfQqjfKIxB2IWbXiEG4N 1qnlfBjgEmCTb69zvJ31L3tjJiccFO6bZbRPrpRFG0WK9TtTJowogqFgZikIrhK2T7R5 1TRRPLWKw4PFPHLbu71uHwB8VvIF48sD65bMOippLMSKmoV/HU8+OTXUJfIC2Rb2hrHW /OUw== MIME-Version: 1.0 X-Received: by 10.52.120.114 with SMTP id lb18mr303641vdb.23.1375794906403; Tue, 06 Aug 2013 06:15:06 -0700 (PDT) In-Reply-To: References: <520058D7.10105@Gmail.com> <5200D210.9030003@Gmail.com> Date: Tue, 6 Aug 2013 14:15:06 +0100 Subject: Re: Sort lines in a plain text file alphanumerically From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375794915 news.xs4all.nl 15905 [2001:888:2000:d::a6]:56233 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52038 On Tue, Aug 6, 2013 at 12:44 PM, Joshua Landau wrote: > On 6 August 2013 11:52, Chris Angelico wrote: >> On Tue, Aug 6, 2013 at 11:38 AM, Devyn Collier Johnson >> wrote: >>> with open('/home/collier/pytest/sort.TXT') as file: >>> sorted(file, key=str.casefold, reverse=True) >>> >>> >>> Thanks for the advice Joshua. I find these tips very useful. However, how >>> would I close the files, or would they close after the "with" construct is >>> complete? >> >> >> That's the whole point of 'with'. It calls open(), > > To be pedantic, it does not. open is called by the time the with gets involved. > The entire statement does. Yes, it's not 'with' that does that, but it is called. Anyway, that's detaily stuff :) ChrisA