Handling 3 operands in an expression without raising an exception
Νίκος
nikos.gr33k at gmail.com
Sun Sep 29 06:17:36 EDT 2013
Στις 29/9/2013 12:50 μμ, ο/η Dave Angel έγραψε:
> ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
> os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
> try:
> gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')
> city = gi.time_zone_by_addr( ipval )
> host = socket.gethostbyaddr( ipval ) [0]
> except socket.gaierror as e:
> gi,city,host=globals().get("gi", "who knows"), globals().get("city",
> "Άγνωστη Πόλη"), globals().get("host", "Άγνωστη
> Προέλευση")
Hello Dave,
By looking at your code i think that you are tellign the progrma to try
to gri don't know what the function globals() is supposed to do
but i was thinking more of:
ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
try:
city = gi.time_zone_by_addr( ipval )
host = socket.gethostbyaddr( ipval ) [0]
except socket.gaierror as e:
# We need something here to identify which one of the 2 above variables
or even both of them went wrong, and then assign the appropriate value
to each one of them but i don't know how to write it.
Is there a function that can tell us which variable failed to be
assigned a value that we can use in order to decide to which variable we
will
More information about the Python-list
mailing list