Felipe Almeida Lessa wrote: > Em Qua, 2006-04-19 às 16:54 -0700, mwt escreveu: > > This works when I try it, but I feel vaguely uneasy about putting > > method calls in exception blocks. > > What do you put in exception blocks?!
Usually I just print an error message. > > > > So tell me, Brave Pythoneers, is this > > evil sorcery that I will end up regretting, or is it just plain good > > ol' Python magic? > > IMHO, the exception block in Python is used a lot in places where you > could use an if-then-else, like your example that could be written as > > if internet_available(): > [...] #doing some internet stuff > else: > alternate_method_that_doesnt_need_internet() > > So yes, I think there's no problem there. > Normally I don't like to use exception blocks to do condition-statement stuff. At least that is how my Java training has programmed me. But in this case, the condition is whether the internet connection is working or not, and I don't see any other way to do it. And furthermore, I don't know if the exceptions-as-logic is a no-no in Python. Hence the question. -- http://mail.python.org/mailman/listinfo/python-list