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. -- https://mail.python.org/mailman/listinfo/python-list