Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.018 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'received:134': 0.05; 'failing': 0.07; 'variables': 0.07; '[0]': 0.09; 'properly.': 0.09; 'so?': 0.09; 'runs': 0.10; "wouldn't": 0.14; 'beautifully': 0.16; 'illustrates': 0.16; 'illustrating': 0.16; 'subject:exception': 0.16; 'subject:expression': 0.16; 'throw': 0.16; 'exception': 0.16; 'code.': 0.18; '>>>': 0.22; 'shell': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; "shouldn't": 0.24; 'environment': 0.24; 'read,': 0.26; 'header:In-Reply-To:1': 0.27; 'installed': 0.27; 'host': 0.29; "doesn't": 0.30; "i'm": 0.30; 'work.': 0.31; 'code': 0.31; 'easier': 0.31; 'too.': 0.31; '"",': 0.31; '>>>>': 0.31; 'file': 0.32; '(most': 0.33; 'checking': 0.33; 'guess': 0.33; 'not.': 0.33; 'basic': 0.35; 'display': 0.35; 'problem.': 0.35; 'something': 0.35; 'prepare': 0.35; 'test': 0.35; 'but': 0.35; 'doing': 0.36; 'should': 0.36; 'skip:o 20': 0.38; 'server': 0.38; 'skip:[ 10': 0.38; 'to:addr :python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'even': 0.60; 'skip:u 10': 0.60; 'skip:o 30': 0.61; 'name': 0.63; '8bit%:95': 0.64; 'between': 0.67; 'dont': 0.67; 'yes': 0.68; '8bit%:92': 0.71; 'lack': 0.78; 'end.': 0.84; 'lien': 0.84; 'pardon': 0.84; 'shell,': 0.91 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqEEAOwURFKGuA9G/2dsb2JhbABbgz+De70rgTiDGQEBBAEjDwFFBgsJAhoCBRYLAgIJAwIBAgFFEwgCh3wGjkebVok+iROBKY4vFoJSgTYDl32BL4Rvi1qDJg Date: Thu, 26 Sep 2013 13:07:51 +0200 From: Antoon Pardon User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.12) Gecko/20130116 Icedove/10.0.12 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Handling 3 operands in an expression without raising an exception References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380193672 news.xs4all.nl 15869 [2001:888:2000:d::a6]:39775 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54811 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 "", line 1, in >> 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. -- Antoon Pardon