On 26/9/2013 18:14, Νίκος wrote: > Στις 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.
newlines are still cheap. And they can really help readability. > 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" Simply assign the default values BEFORE the try block, and use pass as the except block. That still doesn't get around the inadvisability of putting those 3 lines in the try block. You still haven't dealt with the gt assignment and its possible exception. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list