Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'charset:iso-8859-7': 0.04; 'assign': 0.07; 'assignment': 0.07; 'string': 0.09; 'exception.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'block.': 0.16; 'cheap.': 0.16; 'host"': 0.16; 'newlines': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:exception': 0.16; 'subject:expression': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'thu,': 0.19; 'value.': 0.19; '>>>': 0.22; 'putting': 0.22; 'this?': 0.23; 'header:User-Agent:1': 0.23; 'error': 0.23; "haven't": 0.24; 'question': 0.24; 'pass': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'host': 0.29; 'wonder': 0.29; "doesn't": 0.30; 'lines': 0.31; 'block,': 0.31; 'sep': 0.31; 'except': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'possible': 0.36; 'should': 0.36; 'handle': 0.38; 'needed': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'simply': 0.61; 'different': 0.65; 'city': 0.66; 'yes': 0.68; 'feeling': 0.68; 'default': 0.69; 'idiotic': 0.84; 'dealt': 0.91; 'wanting': 0.93; 'serious': 0.97; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: Handling 3 operands in an expression without raising an exception Date: Thu, 26 Sep 2013 22:55:41 +0000 (UTC) References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-7 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 174.32.174.35 User-Agent: XPN/1.2.6 (Street Spirit ; Linux) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380236161 news.xs4all.nl 15929 [2001:888:2000:d::a6]:33623 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54855 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