Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed0.kamp.net!newsfeed.kamp.net!news.qsc.de!zen.net.uk!hamilton.zen.co.uk!reader01.nrc01.news.zen.net.uk.POSTED!not-for-mail From: Nobody Subject: Re: Handling 3 operands in an expression without raising an exception Date: Thu, 26 Sep 2013 09:55:29 +0100 User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) Message-Id: Newsgroups: comp.lang.python References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lines: 22 Organization: Zen Internet NNTP-Posting-Host: 2da6b724.news.zen.co.uk X-Trace: DXC=KCUeDidI6I9<38Yn?1e`93a0UP_O8AJo<=dR0\ckLKG0WeZ<[7LZNR6^i^MoE?6Y[7M2Z^cWRFGA;K`DLa=na?d8 X-Complaints-To: abuse@zen.co.uk Xref: csiph.com comp.lang.python:54794 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.