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

Slawomir Nowaczyk slawomir.nowaczyk.847 at student.lu.se
Thu Aug 10 16:09:00 EDT 2006


On Thu, 10 Aug 2006 14:32:49 +0000 (GMT)
John Salerno <johnjsal at NOSPAMgmail.com> 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 result of the expression is negative, 
#> because even though it's a problem for my program, it isn't really a 
#> "ValueError," right?

Well, you could always do something like
   try:
      int("-"+text)
Now, this *will* be a real ValueError for negative integers ;-) ;-) ;-)

But no, I am not suggesting that... especially since "-0" is valid.

-- 
 Best wishes,
   Slawomir Nowaczyk
     ( Slawomir.Nowaczyk at cs.lth.se )

COMMAND: A suggestion made to a computer.




More information about the Python-list mailing list