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


Groups > comp.lang.python > #43457

Re: shutil.copyfile is incomplete (truncated)

From Terry Jan Reedy <tjreedy@udel.edu>
Subject Re: shutil.copyfile is incomplete (truncated)
Date 2013-04-12 10:48 -0400
References (1 earlier) <asof5aFknkrU1@mid.individual.net> <5363f8ea-f2a6-4a08-a216-18c6666ba698@googlegroups.com> <asoiq9Flkh1U1@mid.individual.net> <d457256e-a195-4c14-ac7f-0afb6b45dc15@googlegroups.com> <CAPTjJmr+3Jouy4KDSHKYqaJFJOkJwAFQrycFOTS6+jje4evXpw@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.523.1365778206.3114.python-list@python.org> (permalink)

Show all headers | View raw


On 4/12/2013 3:32 AM, Chris Angelico wrote:
> On Fri, Apr 12, 2013 at 4:25 PM, Rob Schneider <rmschne@gmail.com> 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.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

shutil.copyfile is incomplete (truncated) Rob Schneider <rmschne@gmail.com> - 2013-04-11 11:12 -0700
  Re: shutil.copyfile is incomplete (truncated) Neil Cerutti <neilc@norwich.edu> - 2013-04-11 18:53 +0000
    Re: shutil.copyfile is incomplete (truncated) Rob Schneider <rmschne@gmail.com> - 2013-04-11 12:07 -0700
      Re: shutil.copyfile is incomplete (truncated) Neil Cerutti <neilc@norwich.edu> - 2013-04-11 19:55 +0000
        Re: shutil.copyfile is incomplete (truncated) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-12 00:06 +0000
          Re: shutil.copyfile is incomplete (truncated) Cameron Simpson <cs@zip.com.au> - 2013-04-12 11:15 +1000
          Re: shutil.copyfile is incomplete (truncated) Ned Deily <nad@acm.org> - 2013-04-11 18:33 -0700
            Re: shutil.copyfile is incomplete (truncated) Rob Schneider <rmschne@gmail.com> - 2013-04-11 23:32 -0700
              Re: shutil.copyfile is incomplete (truncated) Rob Schneider <rmschne@gmail.com> - 2013-04-11 23:53 -0700
                Re: shutil.copyfile is incomplete (truncated) Ned Deily <nad@acm.org> - 2013-04-12 00:53 -0700
              Re: shutil.copyfile is incomplete (truncated) Rob Schneider <rmschne@gmail.com> - 2013-04-11 23:53 -0700
              Re: shutil.copyfile is incomplete (truncated) Cameron Simpson <cs@zip.com.au> - 2013-04-12 18:26 +1000
                Re: shutil.copyfile is incomplete (truncated) Rob Schneider <rmschne@gmail.com> - 2013-04-12 02:18 -0700
                Re: shutil.copyfile is incomplete (truncated) Chris Angelico <rosuav@gmail.com> - 2013-04-12 19:22 +1000
                Re: shutil.copyfile is incomplete (truncated) Rob Schneider <rmschne@gmail.com> - 2013-04-12 05:07 -0700
                Re: shutil.copyfile is incomplete (truncated) Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-04-12 13:18 +0100
                Re: shutil.copyfile is incomplete (truncated) Rob Schneider <rmschne@gmail.com> - 2013-04-12 05:07 -0700
                Re: shutil.copyfile is incomplete (truncated) Rob Schneider <rmschne@gmail.com> - 2013-04-12 02:18 -0700
                Re: shutil.copyfile is incomplete (truncated) Roy Smith <roy@panix.com> - 2013-04-12 10:57 -0400
                Re: shutil.copyfile is incomplete (truncated) Roy Smith <roy@panix.com> - 2013-04-12 10:54 -0400
            Re: shutil.copyfile is incomplete (truncated) Rob Schneider <rmschne@gmail.com> - 2013-04-11 23:32 -0700
              Re: shutil.copyfile is incomplete (truncated) Roy Smith <roy@panix.com> - 2013-04-12 10:47 -0400
          Re: shutil.copyfile is incomplete (truncated) Rob Schneider <rmschne@gmail.com> - 2013-04-11 23:27 -0700
          Re: shutil.copyfile is incomplete (truncated) Roy Smith <roy@panix.com> - 2013-04-12 10:51 -0400
          Re: shutil.copyfile is incomplete (truncated) 88888 Dihedral <dihedral88888@googlemail.com> - 2013-04-12 08:49 -0700
          Re: shutil.copyfile is incomplete (truncated) Nobody <nobody@nowhere.com> - 2013-04-13 03:33 +0100
            Re: shutil.copyfile is incomplete (truncated) Chris Angelico <rosuav@gmail.com> - 2013-04-13 13:05 +1000
            [OT] Lying hard drives [was Re: shutil.copyfile is incomplete (truncated)] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-13 03:17 +0000
              Re: [OT] Lying hard drives [was Re: shutil.copyfile is incomplete (truncated)] Chris Angelico <rosuav@gmail.com> - 2013-04-13 13:43 +1000
        Re: shutil.copyfile is incomplete (truncated) Rob Schneider <rmschne@gmail.com> - 2013-04-11 23:25 -0700
          Re: shutil.copyfile is incomplete (truncated) Chris Angelico <rosuav@gmail.com> - 2013-04-12 17:32 +1000
          Re: shutil.copyfile is incomplete (truncated) Terry Jan Reedy <tjreedy@udel.edu> - 2013-04-12 10:48 -0400

csiph-web