[Tutor] Re: Copy without overwrite?
Kent Johnson
kent_johnson at skillsoft.com
Wed Sep 22 13:55:17 CEST 2004
Yes, that is the way the errors are reported to the caller. In your
program, you don't have an exception handler for the call to softcopy() at
the top level so the interpreter will catch the Error and print the details.
Kent
At 01:20 PM 9/22/2004 +0200, Bernard Lebel wrote:
>Hi Kent, I implemented your suggestions. I have one question about the
>error handling thing.
>Do you keep at the end of the loop the raise statement?
>
>if errors:
> raise s.Error, errors
>
>
>Thanks
>Bernard
>
>----- Original Message -----
>From: "Kent Johnson" <kent_johnson at skillsoft.com>
>To: <tutor at python.org>
>Sent: Wednesday, September 22, 2004 12:11 PM
>Subject: Re: [Tutor] Re: Copy without overwrite?
>
>
> > Hi Bernard,
> >
> > Congratulations on getting this working! Of course I have a couple of
> > suggestions :-)
> >
> > - I notice you call shutil.copytree() if the destination directory is not
> > there. This is fine but not necessary - you could just create the directory
> > and call softcopy() again. That would make the program self-contained and
> > maybe easier to understand - it wouldn't have the two different paths for
> > recursion. OTOH you could consider the call to copytree() an optimization,
> > since at that point you know you don't have to check for existence of the
> > destination files anymore. Either way is fine, really.
> >
> > - If you do call copytree() you should change your exception handler. Just
> > like softcopy(), copytree() catches IOError and wraps them in a
> > shutil.Error. The data in the Error is a list of failures. So for the call
> > to copytree(), instead of (or in addition to) catching IOError and creating
> > a new error list entry, you should catch Error and extend your list with
> > the list the Error contains:
> >
> > try:
> > s.copytree( srcname, dstname )
> > print 'DONE'
> > except os.error, why:
> > print 'FAILED'
> > errors.append( ( srcname, dstname,
> > why ) )
> > except (s.Error), why:
> > print 'FAILED'
> > errors.extend( why )
> >
> > Kent
> >
> > At 11:05 AM 9/22/2004 +0200, Bernard Lebel wrote:
> > >Thanks to everyone!
> > >
> > >Attached is my final script, in txt format.
> > >
> > >
> > >Bernard
> > >
> > >
> > >
> > >
> > >_______________________________________________
> > >Tutor maillist - Tutor at python.org
> > >http://mail.python.org/mailman/listinfo/tutor
> >
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
>
>
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list