Handling 3 operands in an expression without raising an exception

Dave Angel davea at davea.name
Thu Sep 26 07:24:57 EDT 2013


On 26/9/2013 06:51, Νίκος wrote:

   <SNIP>
>>>>> socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
>> os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )[0]
>> Traceback (most recent call last):
>>    File "<stdin>", line 1, in <module>
>> socket.gaierror: [Errno -2] Name or service not known
>>
>> You are just illustrating your lack of basic understaning.
>
> I'm surepirsed, becaus eon my domain [superhost.gr] the same lien of 
> code works withnout an error and it display the 'host' fileds properly.
>
> Perhaps its failing via shell or you do not have a web server installed 
> to prepare the enviromental variables or i dont know what else to hink.
>
> But in my website this code runs at the probelm with no problem.
>
In Python 3.3, but not on a web server, I get:


>>> import socket
>>> socket.gethostbyaddr("unknown")[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.gaierror: [Errno -2] Name or service not known
>>> 

Question, do you get the same result on your server?  (You can put the
Greek string in place of "unknown" of course)

If so, then the default value makes no sense;  it'll cause an exception
if it's ever used.  If you insist on sticking to expressions (no
try/catch, no if statements), then perhaps you should default to a
string representing a domain which will always exist.

-- 
DaveA





More information about the Python-list mailing list