Handling 3 operands in an expression without raising an exception

Νίκος nikos.gr33k at gmail.com
Sun Sep 29 07:34:02 EDT 2013


Στις 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.




More information about the Python-list mailing list