Handling 3 operands in an expression without raising an exception

Jussi Piitulainen jpiitula at ling.helsinki.fi
Thu Sep 26 05:20:30 EDT 2013


Νίκος writes:

> > because it raises KeyError exceptions to this:
> >
> > city = gi.time_zone_by_addr( os.environ.get('HTTP_CF_CONNECTING_IP',
> > 'REMOTE_ADDR') )    or "ÎγνÏÏÏη ΠÏλη"
> >
> > host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP',
> > 'REMOTE_ADDR') )[0] or "ÎγνÏÏÏη ΠÏοέλεÏÂÏη"
> >
> > But that doesnt seem to also work.
> > I want to use the get method because i know if it doesnt does detect a
> > dictionary key item than default back what we give it.
> 
> Can you please tell me why my alternative fails to work although i'am
> using the .get method to default to something?

I lost connection.

Absent HTTP_CF_CONNECTING_IP in os.environ, these reduce to

city = ( gi.time_zone_by_addr('REMOTE_ADDR') or
         "ÎγνÏÏÏη ΠÏλη" )

host = ( socket.gethostbyaddr('REMOTE_ADDR')[0] or
         "ÎγνÏÏÏη ΠÏοέλεÏÂÏη" )

so maybe 'REMOTE_ADDR' is not meant to be the actual argument in those
calls. Earlier versions tried to get 'REMOTE_ADDR' from os.environ, I
think.

Try Nobody's piecemeal approach, maybe.



More information about the Python-list mailing list