Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.066 X-Spam-Evidence: '*H*': 0.87; '*S*': 0.00; 'output': 0.05; 'received :mail-vc0-f174.google.com': 0.09; '23,': 0.16; 'dictionary.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'likewise': 0.16; 'once.': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'input': 0.22; 'file.': 0.24; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'received:209.85.220.174': 0.31; 'steven': 0.31; 'though.': 0.31; 'file': 0.32; 'run': 0.32; 'open': 0.33; 'received:209.85': 0.35; 'received:209.85.220': 0.35; 'received:google.com': 0.35; 'searching': 0.37; 'received:209': 0.37; 'skip:o 20': 0.38; 'depends': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; "you're": 0.61; 'close': 0.67; 'line,': 0.68; 'line*': 0.84; 'subject:skip:o 10': 0.84; '*for': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=3QHMPu3TOhWVRBHirCVMdJE7KEbb6vu9Hko8wpK0Ftg=; b=DbW2v4KwchMBPYc+GMm2VTaD+Oq+Sgtf3+CdtDhWxSXs4hZQpfnzXWI3T16ROkdqOy HuFo0mf76BO7yBbGXdtrvLvmoSkd7Q0CXIT3xlblm732AqqpwOyeSGkC6ZF8c/rIA109 TBtFX1EiKiwWDCxGuL7NsrAuKDAIKJVSeQAT30xvOiGJEmU8PjQF/31oXoo9uW2hiNsn 3sahnfGxIIdouEFNVwYySGLuul1WfQhhoepbCBavjEhLd7V9549yDb2lX57o4MhWug3Y r2FCl+S4SE5VQDClFFP69hKTxsciDvQBk0PkB0kuFqusYCV2Eptsa8NskmlY/k4kw8g8 JGdQ== MIME-Version: 1.0 X-Received: by 10.220.109.145 with SMTP id j17mr21016924vcp.34.1366690113352; Mon, 22 Apr 2013 21:08:33 -0700 (PDT) In-Reply-To: <51760754$0$29872$c3e8da3$5496439d@news.astraweb.com> References: <51760754$0$29872$c3e8da3$5496439d@news.astraweb.com> Date: Tue, 23 Apr 2013 14:08:33 +1000 Subject: Re: optomizations 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: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366690116 news.xs4all.nl 2234 [2001:888:2000:d::a6]:57714 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44139 On Tue, Apr 23, 2013 at 2:00 PM, Steven D'Aprano wrote: > Also, you're searching the file system *for every line* in the input > file. Pull this outside of the loop and have it run once: > > if not os.path.exists(outdir): > os.makedirs(outdir) > > Likewise for opening and closing the output file, which you currently > open and close it for every line. It only needs to be opened and closed > once. The outdir depends on the line, though. Hence my suggestion to retain the open files in a dictionary. ChrisA