Hello,

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 "Άγνωστη Πόλη"

host = socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] or socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or "Άγνωστη Προέλευση"

I was under the impression that the 'or' operator was handling this in case one operand was failing but its not the case here.

I believe in a KeyError is missing the expression cannot even be evaluates as Truthy or Falsy.

Then i thought of os.environ.get() to default to something but then again we have 3 operand in the expression.
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to