Re: Why can not catch the inner exception
On 6 7 , 10 53 , "Mark T" <[EMAIL PROTECTED]> wrote: > " " <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > > > > > > > Please see the follow code, I can not catch the exception " IOError" > > raised from shutil.copyfile() , why? > >try: > >if (DEST_TYPE & TYPE_FTP): > >fn = oname > >ftpc.UploadFile(f, fn) > >else: > >fn = os.path.join(dst, oname) > >shutil.copyfile(f, fn) > > > other code > > >except [IOError, FtpcException],why: > >num = 0 > >print >>sys.stderr, "can not copy '%s' to '%s': > > %s"%(f, fn, why) > >ERR_NUM += 1 > > > I must do like this: > >try: > >if (DEST_TYPE & TYPE_FTP): > >fn = oname > >ftpc.UploadFile(f, fn) > >else: > >fn = os.path.join(dst, oname) > >try: > > shutil.copyfile(f, fn) > >except IOError: > > > > > other code > > >except [IOError, FtpcException],why: > >num = 0 > >print >>sys.stderr, "can not copy '%s' to '%s': > > %s"%(f, fn, why) > >ERR_NUM += 1 > > > Thanks! > > , > > Use a tuple (IOError,FtpcException) instead of a list in the except > statement and it works. > > -- - - > > - - Thank you! :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Floating Number format problem
On 6 12 , 3 16 , ici <[EMAIL PROTECTED]> wrote: > On Jun 12, 10:10 am, <[EMAIL PROTECTED]> wrote: > > > > > How could I format the float number like this: (keep 2 digit > > precision) > > 1.002 => 1 > > 1.12 => 1.12 > > 1.00 => 1 > > 1.567 => 1.57 > > 2324.012 => 2324.01 > > > I can not find any Formatting Operations is able to meet my > > requirement. > > Any suggestion will be appreciated. > >>> print "%.02f" % (2324.012) > 2324.01 > > http://docs.python.org/tut/node9.html#SECTION00910 thank you ! But in these case: >>> print '%.02f'%1.002 1.00 >>> print '%.02f'%1.00 1.00 I just expect it to output "1" , but these way will output 1.00 -- http://mail.python.org/mailman/listinfo/python-list
Re: Loop three lists at the same time?
On 11 13 , 6 46 , Davy <[EMAIL PROTECTED]> wrote: > Hi all, > > I have three lists with the same length. Is there any method to loop > the three lists without a loop counter? > > Best regards, > Davy Maybe you just need this:-) >>> list1 = [1, 2, 3] >>> list2 = [4, 5, 6] >>> list3 = [7, 8, 9] >>> for i in list1+list2+list3: ...print i ... -- http://mail.python.org/mailman/listinfo/python-list