Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed2.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'syntax': 0.04; 'assign': 0.07; 'subject:skip:s 10': 0.07; 'string': 0.09; 'f.close()': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '4:25': 0.16; 'bugs.': 0.16; 'code?': 0.16; 'evaluating': 0.16; "function's": 0.16; 'parentheses': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'statement.': 0.16; 'temp': 0.16; '(you': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'command': 0.22; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'instance,': 0.24; '(or': 0.24; 'defined': 0.27; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; 'statement': 0.30; 'file:': 0.31; 'operations.': 0.31; 'text': 0.33; 'fri,': 0.33; 'actual': 0.34; 'could': 0.34; 'subject: (': 0.35; 'problem.': 0.35; 'done.': 0.35; 'object,': 0.36; 'method': 0.36; 'should': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; '12,': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'received:173': 0.61; "you're": 0.61; 'name': 0.63; 'close': 0.67; "'with'": 0.84; 'received:fios.verizon.net': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Jan Reedy Subject: Re: shutil.copyfile is incomplete (truncated) Date: Fri, 12 Apr 2013 10:48:38 -0400 References: <5363f8ea-f2a6-4a08-a216-18c6666ba698@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 In-Reply-To: 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1365778206 news.xs4all.nl 2668 [2001:888:2000:d::a6]:48887 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43457 On 4/12/2013 3:32 AM, Chris Angelico wrote: > On Fri, Apr 12, 2013 at 4:25 PM, Rob Schneider wrote: >> >>> The close method is defined and flushing and closing a file, so >>> >>> it should not return until that's done. >>> >>> >>> >>> What command are you using to create the temp file? >>> >>> >> >> re command to write the file: >> f=open(fn,'w') >> ... then create HTML text in a string >> f.write(html) >> f.close > > Hold it one moment... You're not actually calling close. The file's > still open. Is that a copy/paste problem, or is that your actual code? > > In Python, a function call ALWAYS has parentheses after it. Evaluating > a function's name like that returns the function (or method) object, > which you then do nothing with. (You could assign it someplace, for > instance, and call it later.) Try adding empty parens: > > f.close() > > and see if that solves the problem. Alternatively, look into the > 'with' statement and the block syntax that it can give to I/O > operations. I say *definitely* use a 'with' statement. Part of its purpose is to avoid close bugs.