Στις 5/7/2013 9:55 πμ, ο/η Lele Gaifax έγραψε:
Ferrous Cranus <ni...@superhost.gr> writes:

host =  gethostbyaddr(....) or "UnResolved"

This will return the first argument that define the evaluation as
being true or untrue.

if function returns false the the 2nd argument.
Nut if the function gives an exception will the condition return the
2nd argument or will the program fail?

I was udner the impression that i could avoid error handling  inside
try/excepts by utilizing "or".

No, you had the wrong impression. Why don't you simply invoke the Python
interpreter and try things out with that??

     >>> a = 1/0 or 100
     Traceback (most recent call last):
       File "<stdin>", line 1, in <module>
     ZeroDivisionError: division by zero
     >>> a
     Traceback (most recent call last):
       File "<stdin>", line 1, in <module>
     NameError: name 'a' is not defined
     >>> a = 0/1 or 100
     >>> a
     100
     >>>

Thank you Lele, i wanted to but i had no idea how to test it.
Your devision by zero is very smart thing to test!

So it proves that a condition cannot be evaluation as truthy or falsey if one of the operators is giving out an exception.
Thank you.


--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to