Re: common mistakes in this simple program

2016-03-15 Thread Ganesh Pal
On Tue, Mar 1, 2016 at 2:41 AM, Martin A. Brown wrote: > Please read below. I will take a stab at explaining the gaps of > understanding you seem to have (others have tried already, but I'll > try, as well). > > I am going to give you four different functions which

Re: common mistakes in this simple program

2016-03-01 Thread Steven D'Aprano
On Tue, 1 Mar 2016 03:29 am, Ian Kelly wrote: > On Mon, Feb 29, 2016 at 8:18 AM, Ganesh Pal wrote: >> Iam on python 2.6 > > Python 2.6 has been unsupported since October 2013. Among other > things, that means it is no longer receiving security updates like > more recent

Re: common mistakes in this simple program

2016-02-29 Thread Ian Kelly
On Mon, Feb 29, 2016 at 4:14 PM, Cameron Simpson wrote: > Another remark here: if you're going to log, log the exception as well: > > logging.error("something went wrong: %s", e) > > Ian's example code is nice and simple to illustrate "log and then reraise" > but few things

Re: common mistakes in this simple program

2016-02-29 Thread Rob Gaddi
Cameron Simpson wrote: > On 29Feb2016 10:45, Ian Kelly wrote: >>On Mon, Feb 29, 2016 at 10:26 AM, Ganesh Pal wrote: >>> On Mon, Feb 29, 2016 at 9:59 PM, Ian Kelly wrote: On Mon, Feb 29, 2016 at 8:18 AM, Ganesh Pal

Re: common mistakes in this simple program

2016-02-29 Thread Cameron Simpson
On 29Feb2016 10:45, Ian Kelly wrote: On Mon, Feb 29, 2016 at 10:26 AM, Ganesh Pal wrote: On Mon, Feb 29, 2016 at 9:59 PM, Ian Kelly wrote: On Mon, Feb 29, 2016 at 8:18 AM, Ganesh Pal wrote: 1. usage

Re: common mistakes in this simple program

2016-02-29 Thread Martin A. Brown
Greetings Ganesh, >> You're falling into the trap of assuming that the only exception you >> can ever get is the one that you're planning for, and then handling. > >Ok sure ! This point is very important, so I'll reiterate it. I hope the poor horse lives. >> ALL exceptions as though they

Re: common mistakes in this simple program

2016-02-29 Thread Marko Rauhamaa
sohcahto...@gmail.com: > Every time you say "try-expect", my head wants to explode. > > It is called a "try-except" block, because you're using the key words > "try" and "except" when you make one. Ah, I remember a Python-based test system idea where the "except" keyword meant "expect":

Re: common mistakes in this simple program

2016-02-29 Thread Joel Goldstick
On Mon, Feb 29, 2016 at 2:49 PM, Ganesh Pal wrote: > On Mar 1, 2016 12:06 AM, "Chris Angelico" wrote > > > > You're falling into the trap of assuming that the only exception you > > can ever get is the one that you're planning for, and then handling. > >

Re: common mistakes in this simple program

2016-02-29 Thread Ganesh Pal
On Mar 1, 2016 12:06 AM, "Chris Angelico" wrote > > You're falling into the trap of assuming that the only exception you > can ever get is the one that you're planning for, and then handling. Ok sure ! > ALL exceptions as though they were that one. Instead catch ONLY the >

Re: common mistakes in this simple program

2016-02-29 Thread sohcahtoa82
On Monday, February 29, 2016 at 10:21:57 AM UTC-8, Ganesh Pal wrote: > >> How do we reraise the exception in python , I have used raise not > >> sure how to reraise the exception > > > > raise with no arguments will reraise the exception currently being handled. > > > > except Exception: > >

Re: common mistakes in this simple program

2016-02-29 Thread Chris Angelico
On Tue, Mar 1, 2016 at 5:21 AM, Ganesh Pal wrote: > > In my case the exception is nothing but the error example if we plan > to run the command say #ifconfig -a and the command fails because of > a type ( say u ran #igconfig -a). > > we will the output as > > # Failed to

Re: common mistakes in this simple program

2016-02-29 Thread Ganesh Pal
>> How do we reraise the exception in python , I have used raise not >> sure how to reraise the exception > > raise with no arguments will reraise the exception currently being handled. > > except Exception: > logging.error("something went wrong") > raise Thanks Ian for taking time and

Re: common mistakes in this simple program

2016-02-29 Thread Ian Kelly
On Mon, Feb 29, 2016 at 10:26 AM, Ganesh Pal wrote: > On Mon, Feb 29, 2016 at 9:59 PM, Ian Kelly wrote: >> On Mon, Feb 29, 2016 at 8:18 AM, Ganesh Pal wrote: >>> Iam on python 2.6 > >>> 1. usage of try- expect >> >> try-except

Re: common mistakes in this simple program

2016-02-29 Thread Ganesh Pal
On Mon, Feb 29, 2016 at 9:59 PM, Ian Kelly wrote: > On Mon, Feb 29, 2016 at 8:18 AM, Ganesh Pal wrote: >> Iam on python 2.6 >> 1. usage of try- expect > > try-except in every single function is a code smell. You should only > be using it where you're

Re: common mistakes in this simple program

2016-02-29 Thread Ian Kelly
On Mon, Feb 29, 2016 at 8:18 AM, Ganesh Pal wrote: > Iam on python 2.6 Python 2.6 has been unsupported since October 2013. Among other things, that means it is no longer receiving security updates like more recent versions. Unless you have an extremely strong reason for