Handling 3 operands in an expression without raising an exception

Νίκος nikos.gr33k at gmail.com
Thu Sep 26 18:14:45 EDT 2013


Στις 26/9/2013 11:16 μμ, ο/η Denis McMahon έγραψε:
> On Thu, 26 Sep 2013 19:58:02 +0300, Νίκος wrote:
>
>> except socket.gaierror as e:
>> 	city = host = "UnKnown Origin"
>>
>> But then what if in case of an error i needed different string set to be
>> assigned on city and host respectively?
>
> Oh FFS
>
> Are you serious when you ask this?
>
> Simply change:
>
> except socket.gaierror as e:
>      city = host = "UnKnown Origin"
>
> To:
>
> except socket.gaierror as e:
>      city = "Unknown City"
>      host = "Unknown Host"

Yes indeed that was an idiotic question made by me, but i was somehow 
feeling again that i should handle it in one-liner, avoid wanting to use 
2 statements.

I wonder if there is a way to assign the string "Unknown Origin" to the 
variable that failed in the try block to get a value.

Can i describe that somehow inside the except block?

I mean like:

except socket.gaierror as e:
	what_ever_var_failed = "Unknown Origin"



More information about the Python-list mailing list