Re: Pythonic API design: detailed errors when you usually don't care

2006-10-03 Thread John J. Lee
"Simon Willison" <[EMAIL PROTECTED]> writes: > Hi all, > > I have an API design question. I'm writing a function that can either > succeed or fail. Most of the time the code calling the function won't > care about the reason for the failure, but very occasionally it will. > > I can see a number

Re: Pythonic API design: detailed errors when you usually don't care

2006-10-02 Thread Kay Schluehr
Simon Willison wrote: > Hi all, > > I have an API design question. I'm writing a function that can either > succeed or fail. Most of the time the code calling the function won't > care about the reason for the failure, but very occasionally it will. > > I can see a number of ways of doing this, bu

Re: Pythonic API design: detailed errors when you usually don't care

2006-10-02 Thread Aahz
In article <[EMAIL PROTECTED]>, Simon Willison <[EMAIL PROTECTED]> wrote: > >try: > do_something() >except HttpError: > # An HTTP error occurred >except ApplicationError: > # An application error occurred >else: > # It worked! Use a similar but different idiom: try: do_something() except

Re: Pythonic API design: detailed errors when you usually don't care

2006-10-02 Thread Paul Rubin
Steve Holden <[EMAIL PROTECTED]> writes: > I should have thought the simplest spelling of your requirements would be > > try: > do_something() > print "It worked" > except: > # it didn't This usage is generally disparaged because of the possibility of exceptions having nothing to d

Re: Pythonic API design: detailed errors when you usually don't care

2006-10-02 Thread Steve Holden
Steve Holden wrote: > Simon Willison wrote: > >>Hi all, >> >>I have an API design question. I'm writing a function that can either >>succeed or fail. Most of the time the code calling the function won't >>care about the reason for the failure, but very occasionally it will. >> >>I can see a number

Re: Pythonic API design: detailed errors when you usually don't care

2006-10-02 Thread Carl Banks
Simon Willison wrote: > I have an API design question. I'm writing a function that can either > succeed or fail. Most of the time the code calling the function won't > care about the reason for the failure, but very occasionally it will. > > I can see a number of ways of doing this, but none of th

Re: Pythonic API design: detailed errors when you usually don't care

2006-10-02 Thread Steve Holden
Simon Willison wrote: > Hi all, > > I have an API design question. I'm writing a function that can either > succeed or fail. Most of the time the code calling the function won't > care about the reason for the failure, but very occasionally it will. > > I can see a number of ways of doing this, b

Re: Pythonic API design: detailed errors when you usually don't care

2006-10-02 Thread Sybren Stuvel
Simon Willison enlightened us with: > try: > do_something() > except HttpError: > # An HTTP error occurred > except ApplicationError: > # An application error occurred > else: > # It worked! > > This does the job fine, but has a couple of problems. > I anticipate that most people using my

Pythonic API design: detailed errors when you usually don't care

2006-10-02 Thread Simon Willison
Hi all, I have an API design question. I'm writing a function that can either succeed or fail. Most of the time the code calling the function won't care about the reason for the failure, but very occasionally it will. I can see a number of ways of doing this, but none of them feel aesthetically p