Re: converting a nested try/except statement into try/except/else

2006-08-11 Thread John Salerno
Simon Forman wrote: > I'm sorry to hear that. I thought it was cleaner and more > understandable than that. May I indulge in explaining it a bit? I > can, perhaps, make it clearer. Thanks for the explanation. I find that with a little concentration, it's not that it's hard to follow the code,

Re: converting a nested try/except statement into try/except/else

2006-08-11 Thread John Salerno
Boris Borcic wrote: > Boris Borcic wrote: >> John Salerno wrote: >>> In this case the method must return False, because it's a wxPython >>> method that needs a True or False value. If it doesn't, the program >>> will continue even after the error message. >> >> Just as it should do if the method

Re: converting a nested try/except statement into try/except/else

2006-08-11 Thread Slawomir Nowaczyk
On Thu, 10 Aug 2006 16:42:47 -0700 Simon Forman <[EMAIL PROTECTED]> wrote: #> 6.) There's a single return statement. #> #> I forget now where I picked this up, but it's served me well for #> many years: Procedures, functions, methods, etc... should have one #> exit point. Something about having f

Re: converting a nested try/except statement into try/except/else

2006-08-10 Thread Simon Forman
John Salerno wrote: > Simon Forman wrote: > > > What about the version I gave you 8 days ago? ;-) > > > > http://groups.google.ca/group/comp.lang.python/msg/a80fcd8932b0733a > > > > It's clean, does the job, and doesn't have any extra nesting. > > > > Peace, > > ~Simon > > > > I remember that versi

Re: converting a nested try/except statement into try/except/else

2006-08-10 Thread Boris Borcic
Boris Borcic wrote: > John Salerno wrote: >> In this case the method must return False, because it's a wxPython >> method that needs a True or False value. If it doesn't, the program >> will continue even after the error message. > > Just as it should do if the method returns True and no error m

Re: converting a nested try/except statement into try/except/else

2006-08-10 Thread Boris Borcic
John Salerno wrote: > In this case the method must return False, because it's a wxPython > method that needs a True or False value. If it doesn't, the program will > continue even after the error message. Just as it should do if the method returns True and no error message is produced if I und

Re: converting a nested try/except statement into try/except/else

2006-08-10 Thread Boris Borcic
Bruno Desthuilliers wrote: > Boris Borcic a écrit : >> Slawomir Nowaczyk wrote: >> >>> >>> try: >>> if int(text) > 0: >>>return True >>> except ValueError: >>> pass >>> self.error_message() >>> return False >>> >> >> Nicely DRY. To make it even more compact, it may be noticed that t

Re: converting a nested try/except statement into try/except/else

2006-08-10 Thread John Salerno
Boris Borcic wrote: > Slawomir Nowaczyk wrote: >> >> try: >> if int(text) > 0: >>return True >> except ValueError: >> pass >> self.error_message() >> return False >> > > Nicely DRY. To make it even more compact, it may be noticed that the > default return value None is false in a

Re: converting a nested try/except statement into try/except/else

2006-08-10 Thread Bruno Desthuilliers
Boris Borcic a écrit : > Slawomir Nowaczyk wrote: > >> >> try: >> if int(text) > 0: >>return True >> except ValueError: >> pass >> self.error_message() >> return False >> > > Nicely DRY. To make it even more compact, it may be noticed that the > default return value None is false

Re: converting a nested try/except statement into try/except/else

2006-08-10 Thread Boris Borcic
Slawomir Nowaczyk wrote: > > try: > if int(text) > 0: >return True > except ValueError: > pass > self.error_message() > return False > Nicely DRY. To make it even more compact, it may be noticed that the default return value None is false in a boolean context - so that the last

Re: converting a nested try/except statement into try/except/else

2006-08-10 Thread Slawomir Nowaczyk
On Thu, 10 Aug 2006 14:32:49 + (GMT) John Salerno <[EMAIL PROTECTED]> wrote: #> Bruno Desthuilliers wrote: #> #> > try: #> > if int(text) <= 0: raise ValueError #> #> Hmm, I'm actually not so sure about this line now. It doesn't seem right #> to raise a ValueError when the res

Re: converting a nested try/except statement into try/except/else

2006-08-10 Thread Bruno Desthuilliers
John Salerno a écrit : > Bruno Desthuilliers wrote: > >> try: >> if int(text) <= 0: raise ValueError > > > Hmm, I'm actually not so sure about this line now. It doesn't seem right > to raise a ValueError when the result of the expression is negative, > because even though it's a

Re: converting a nested try/except statement into try/except/else

2006-08-10 Thread infidel
> > try: > > if int(text) <= 0: raise ValueError > > Hmm, I'm actually not so sure about this line now. It doesn't seem right > to raise a ValueError when the result of the expression is negative, > because even though it's a problem for my program, it isn't really a > "ValueError," r

Re: converting a nested try/except statement into try/except/else

2006-08-10 Thread Slawomir Nowaczyk
On Wed, 09 Aug 2006 18:51:04 + (GMT) John Salerno <[EMAIL PROTECTED]> wrote: #> try: #> int(text) #> except ValueError: #> self.error_message() #> return False #> else: #> return True #> #> I think it's much cleaner, but obviously I lost the test in the #> original if stat

Re: converting a nested try/except statement into try/except/else

2006-08-10 Thread John Salerno
Bruno Desthuilliers wrote: > try: > if int(text) <= 0: raise ValueError Hmm, I'm actually not so sure about this line now. It doesn't seem right to raise a ValueError when the result of the expression is negative, because even though it's a problem for my program, it isn't really

Re: converting a nested try/except statement into try/except/else

2006-08-10 Thread John Salerno
Simon Forman wrote: > What about the version I gave you 8 days ago? ;-) > > http://groups.google.ca/group/comp.lang.python/msg/a80fcd8932b0733a > > It's clean, does the job, and doesn't have any extra nesting. > > Peace, > ~Simon > I remember that version, but I found it a little hard to foll

Re: converting a nested try/except statement into try/except/else

2006-08-10 Thread John Salerno
Bruno Desthuilliers wrote: > try: > if int(text) <= 0: raise ValueError > except ValueError: > self.error_message() > return False > else: > return True Nice! Thanks! -- http://mail.python.org/mailman/listinfo/python-list

Re: converting a nested try/except statement into try/except/else

2006-08-09 Thread Bruno Desthuilliers
Bruno Desthuilliers a écrit : > John Salerno a écrit : > (snip) or of course the dead simple: try: if int(text) <= 0: raise ValueError except ValueError: self.error_message() return False else: return True BTW, you really should have a

Re: converting a nested try/except statement into try/except/else

2006-08-09 Thread Simon Forman
John Salerno wrote: > I'm starting out with this: > > try: > if int(text) > 0: > return True > else: > self.error_message() > return False > except ValueError: > self.error_message() > return False > > I rewrote it as this: > > try: > int(text) >

Re: converting a nested try/except statement into try/except/else

2006-08-09 Thread Bruno Desthuilliers
John Salerno a écrit : > I'm starting out with this: > > try: > if int(text) > 0: > return True > else: > self.error_message() > return False > except ValueError: > self.error_message() > return False > > I rewrote it as this: > > try: > int(text) > ex

converting a nested try/except statement into try/except/else

2006-08-09 Thread John Salerno
I'm starting out with this: try: if int(text) > 0: return True else: self.error_message() return False except ValueError: self.error_message() return False I rewrote it as this: try: int(text) except ValueError: self.error_message() r