Handling 3 operands in an expression without raising an exception

Νίκος nikos.gr33k at gmail.com
Thu Sep 26 07:25:55 EDT 2013


Στις 26/9/2013 2:07 μμ, ο/η Antoon Pardon έγραψε:
> Op 26-09-13 12:51, Νίκος schreef:
>> Στις 26/9/2013 1:41 μμ, ο/η Antoon Pardon έγραψε:
>>> Op 26-09-13 12:18, Νίκος schreef:
>>>> Στις 26/9/2013 1:12 μμ, ο/η Antoon Pardon έγραψε:
>>>>> Op 26-09-13 11:56, Νίκος schreef:
>>>>
>>>> It is far better than the ifs, even easier to read, i was just missing a
>>>> [0] at the end.
>>>>
>>>> host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
>>>> os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )[0]
>>>
>>> No it is not. Your purpose was to have a line that wouldn't throw an
>>> exception even if some environ variables were not available. That
>>> means it shouldn't throw an exception when I execute the code. Guess
>>> what happens:
>>>
>>>>>> 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.
>
> You shoudn't be. This illustrates beautifully the difference between
> understanding what one is doing and dabbling around until one stumbles
> on something that currently works but that will stop working in other
> circumstances.
>
>> 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.
>
> Yes it is failing via shell, but that doesn't matter. If your purpose
> was to have that line working even if the environ variables were not
> available, then the line should work from a shell too.
>
>> But in my website this code runs at the probelm with no problem.
>
> So? That just means that your website is not a good test environment
> for checking whether the code works under all circumstances you want
> it to work.
>
Okey then please tell me, what do you see wrong in it:

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

the [0] at then end in case the statemnt default to the string?
please tell me in details what might go wrong with it so i cna 
understand it.



More information about the Python-list mailing list