Re: inline exception handling in python

2010-08-12 Thread Steven D'Aprano
On Thu, 12 Aug 2010 14:19:13 -0400, wheres pythonmonks wrote: > I think the problem in my case is best solved by look before you leap, > or a wrapper function. [I just hate function call overhead for this. ] Sounds suspiciously like premature micro-optimization to me. Function call overhead is

Re: inline exception handling in python

2010-08-12 Thread Steven D'Aprano
On Thu, 12 Aug 2010 20:08:01 +0200, Thomas Jollans wrote: [...] > Besides, more often than not, you want to have a finally clause around > when you're dealing with exceptions. Oh I don't know about that. Doing a quick and totally unscientific survey of my own code, I find that try...except with n

Re: inline exception handling in python

2010-08-12 Thread Carey Tilden
On Thu, Aug 12, 2010 at 1:18 PM, wheres pythonmonks wrote: > Well I suppose it matters depending on the nature of the data you are > looking at...  But small function calls tend to be the death of interpreted > languages... I would be interested to see a real application that had performance neg

Re: inline exception handling in python

2010-08-12 Thread wheres pythonmonks
On Thu, Aug 12, 2010 at 2:57 PM, Thomas Jollans wrote: > On Thursday 12 August 2010, it occurred to wheres pythonmonks to exclaim: >> [I just hate function call overhead for this.] > > I think you've got your priorities wrong. If you want to avoid unnecessary > overhead, avoid exceptions more than

Re: inline exception handling in python

2010-08-12 Thread Thomas Jollans
On Thursday 12 August 2010, it occurred to wheres pythonmonks to exclaim: > [I just hate function call overhead for this.] I think you've got your priorities wrong. If you want to avoid unnecessary overhead, avoid exceptions more than functions. -- http://mail.python.org/mailman/listinfo/python

Re: inline exception handling in python

2010-08-12 Thread wheres pythonmonks
On Thu, Aug 12, 2010 at 2:42 PM, MRAB wrote: > wheres pythonmonks wrote: >> >> Hi! >> >> I have on a few occasions now wanted to have inline-exception >> handling, like the inline if/else operator. >> >> For example, >> >> The following might raise ZeroDivisionError: >> >> f = n / d >> >> So, I ca

Re: inline exception handling in python

2010-08-12 Thread MRAB
wheres pythonmonks wrote: Hi! I have on a few occasions now wanted to have inline-exception handling, like the inline if/else operator. For example, The following might raise ZeroDivisionError: f = n / d So, I can look before I leap (which is okay): f = float("nan") if d == 0 else n/d; But

Re: inline exception handling in python

2010-08-12 Thread wheres pythonmonks
On Thu, Aug 12, 2010 at 2:19 PM, wheres pythonmonks wrote: > On Thu, Aug 12, 2010 at 2:08 PM, Thomas Jollans wrote: >> On Thursday 12 August 2010, it occurred to wheres pythonmonks to exclaim: >>> try: >>>    f = n / d >>> except: >>>    f = float("nan") >> >> A catch-all except clause. Never a g

Re: inline exception handling in python

2010-08-12 Thread wheres pythonmonks
On Thu, Aug 12, 2010 at 2:08 PM, Thomas Jollans wrote: > On Thursday 12 August 2010, it occurred to wheres pythonmonks to exclaim: >> try: >>    f = n / d >> except: >>    f = float("nan") > > A catch-all except clause. Never a good idea. It's not as bad in this case, as > there is only one expres

Re: inline exception handling in python

2010-08-12 Thread Thomas Jollans
On Thursday 12 August 2010, it occurred to wheres pythonmonks to exclaim: > try: >f = n / d > except: >f = float("nan") A catch-all except clause. Never a good idea. It's not as bad in this case, as there is only one expression, but there are still a couple of other exceptions that have

inline exception handling in python

2010-08-12 Thread wheres pythonmonks
Hi! I have on a few occasions now wanted to have inline-exception handling, like the inline if/else operator. For example, The following might raise ZeroDivisionError: f = n / d So, I can look before I leap (which is okay): f = float("nan") if d == 0 else n/d; But, what I'd like to be able t