Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'charset:iso-8859-7': 0.04; 'assign': 0.07; 'string': 0.09; '[0]': 0.09; 'exception,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'try:': 0.09; "'w')": 0.16; '(%s):': 0.16; 'belongs': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:exception': 0.16; 'subject:expression': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'skip:p 40': 0.19; 'solution.': 0.20; 'seems': 0.21; 'header:User-Agent:1': 0.23; 'stick': 0.24; 'header:X-Complaints-To:1': 0.27; 'host': 0.29; 'there,': 0.34; "can't": 0.35; 'except': 0.35; 'but': 0.35; 'really': 0.36; "i'll": 0.36; 'should': 0.36; 'skip:o 20': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:o 30': 0.61; 'back': 0.62; "you've": 0.63; 'city': 0.66; 'default': 0.69; 'vars': 0.91; 'hand,': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: Handling 3 operands in an expression without raising an exception Date: Sun, 29 Sep 2013 11:27:57 +0000 (UTC) References: <20130928183833.GA13630@piedra> <5247f760$0$29988$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-7 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 174.32.174.35 User-Agent: XPN/1.2.6 (Street Spirit ; Linux) 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380454099 news.xs4all.nl 15999 [2001:888:2000:d::a6]:55842 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:55010 On 29/9/2013 07:14, Νίκος wrote: > Dave's way though seems better. > Assign the vars default string and if they get re-assinged correctly > that would be ideal, otherwise we have already given them the defaults. > > ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or > os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) > city = "Άγνωστη Πόλη" > host = "Άγνωστη Προέλευση" > try: > gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat') > city = gi.time_zone_by_addr( ipval ) > host = socket.gethostbyaddr( ipval ) [0] > except Exception as e: > print( "metrites.py => (%s): " % lastvisit, repr( sys.exc_info() ), > file=open('/tmp/err.out', 'w') ) > > I'll think i'll stick to this solution. > But you've put gi back in to the try-block. If it really belongs there, then you'd better give it a default value as well. On the other hand, if it can't get an exception, you should move it out. -- DaveA