Handling 3 operands in an expression without raising an exception

Denis McMahon denismfmcmahon at gmail.com
Sun Sep 29 17:15:44 EDT 2013


On Sun, 29 Sep 2013 14:34:02 +0300, Νίκος wrote:

> Στις 29/9/2013 2:27 μμ, ο/η Dave Angel έγραψε:
>> 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.
> 
> You are right i just put it there because its being relevant to the
> whole geoip things. Givign it a default value will not really help much
> because i'am not printing it later on it just is necessay to poitn to an
> existing geopip file in plcace.
> 
> If it fails to be assinged then i will just cat /etc/err/out and see
> that it erred out and then take action to fix it.

Nick, you have now spent 4 days arguing over a minor coding problem that 
you were given solutions to on the first day, primarily because you feel 
that the solutions you are being offend some programming aesthetic you 
have.

I suggest that it's time for you to re-evaluate what you want from this 
ng, and indeed what language you want to code in if your perl "minimal 
code possible" aesthetic is so important to you.

If you want good python code, then stop telling everyone here that their 
working solutions are wrong and should be more like your dysfunctional 
code, and use the solutions you are given.

If you want to write minimalist perl code, then stop using python and use 
perl.

In either case, you need to stop arguing with people who are offering you 
solutions to your problems solely based on the fact that you don't like 
their coding styles.

You are the one who comes here asking for solutions. Either accept the 
solutions you are offered, or stop asking for them.

-- 
Denis McMahon, denismfmcmahon at gmail.com



More information about the Python-list mailing list