Handling 3 operands in an expression without raising an exception

Νίκος nikos.gr33k at gmail.com
Thu Sep 26 08:39:22 EDT 2013


Στις 26/9/2013 2:24 μμ, ο/η Dave Angel έγραψε:
> 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.

Yes, you are right, in my shell it fails too givign the same error 
message as yours, while on the other had in the websste is working.

Can you explain this please?
why doesnt it fail to both enviroments?




More information about the Python-list mailing list