Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.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.070 X-Spam-Evidence: '*H*': 0.86; '*S*': 0.00; 'received:134': 0.05; 'though:': 0.07; 'lines:': 0.09; 'logic': 0.09; 'wrote': 0.14; 'likewise': 0.16; 'missing?': 0.16; 'subject:exception': 0.16; 'subject:expression': 0.16; 'throw': 0.16; 'wrote:': 0.18; 'thu,': 0.19; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'least': 0.26; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'host': 0.29; "doesn't": 0.30; 'lines': 0.31; 'sep': 0.31; 'but': 0.35; 'next': 0.36; 'should': 0.36; 'too': 0.37; 'two': 0.37; 'clear': 0.37; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'skip:o 30': 0.61; 'simple': 0.61; 'you.': 0.62; 'more': 0.64; '8bit%:95': 0.64; 'forward': 0.65; 'city': 0.66; 'nobody': 0.68; '8bit%:92': 0.71; '8bit%:97': 0.74; 'pardon': 0.84; 'skip:\xc3 10': 0.91; '2013': 0.98 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqIEAP4HRFKGuA9G/2dsb2JhbABbgz+De7ougnqBOIMZAQEEASMPAUUGCwkCGAICBRYLAgIJAwIBAgFFEwgCh3wGjiebVok6iROBKY4vFoJSgTYDl32GHotagyY Date: Thu, 26 Sep 2013 12:12:23 +0200 From: Antoon Pardon User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.12) Gecko/20130116 Icedove/10.0.12 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Handling 3 operands in an expression without raising an exception References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380190345 news.xs4all.nl 15971 [2001:888:2000:d::a6]:46296 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54804 Op 26-09-13 11:56, Νίκος schreef: > Στις 26/9/2013 11:55 πμ, ο/η Nobody έγραψε: >> On Thu, 26 Sep 2013 10:26:48 +0300, Νίκος wrote: >> >>> How can i wrote the two following lines so for NOT to throw out >>> KeyErrors when a key is missing? >>> >>> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or >>> gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or >>> "Άγνωστη Πόλη" >> >> tz = None >> ip = os.environ.get('HTTP_CF_CONNECTING_IP') >> if ip: >> tz = gi.time_zone_by_addr(ip) >> if not tz: >> ip = os.environ.get('REMOTE_ADDR') >> if ip: >> tz = gi.time_zone_by_addr(ip) >> if not tz: >> tz = "ÎγνÏÏÏη Î Ïλη" >> >> Likewise for the hostname. >> > > Its logic is simple and straightforward but too many lines: > > host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR') or "Άγνωστη Προέλευση" ) > > this is much better in my opinion and straighforward also and more clear > to read: No it is not and you prove that in the very next line. > it doens't work though: If it doesn't do what you think it should do then it is not straight forward or clear, at least not to you. -- Antoon Pardon