Handling 3 operands in an expression without raising an exception

Νίκος nikos.gr33k at gmail.com
Fri Sep 27 06:04:02 EDT 2013


Στις 27/9/2013 12:26 μμ, ο/η Steven D'Aprano έγραψε:
> On Fri, 27 Sep 2013 12:19:53 +0300, Νίκος wrote:
>
>> I'am not sure what you mean though when you say:
>>
>>> Simply assign the default values BEFORE the try block, and use pass as
>>> the except block.
>>
>> Can you please make it more clear for me?
>
>
> variable = "default value"
> try:
>      variable = something_that_might_fail()
> except SomeException:
>      pass

Thanks Steven but this way i still have to declare the default string 
sfor the variables:

Its no different than:

except socket.gaierror as e:
	city = "Άγνωστη Πόλη"
	host = "Άγνωστη Προέλευση"

Your way set the vars on top, the other way set the vars inside the 
except block.




More information about the Python-list mailing list