Convert Latitude, Longitude To TimeZone

Roy Smith roy at panix.com
Sun Mar 31 11:09:14 EDT 2013


In article <mailman.4017.1364741666.2939.python-list at python.org>,
 Steve B <maccten2000 at hotmail.com> wrote:

> I found a piece of code
> [http://blog.pamelafox.org/2012/04/converting-addresses-to-timezones-in.html
> ] which uses the function [https://gist.github.com/pamelafox/2288222]
> 
> When I try to run the code, I get the error geonames is not defined (This is
> the function previously linked to)

The best thing to do when asking questions like this is to copy-paste 
the exact error message you got.  It was probably something like:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'geonames' is not defined

In this example, it's easy enough to figure out what went wrong from 
your description, but in general, giving the exact error helps in the 
diagnosis.

> geonames_client = geonames.GeonamesClient('Username_alpha')
> 
> geonames_result = geonames_client.find_timezone({'lat': 48.871236, 'lng':
> 2.77928})
> 
> user.timezone = geonames_result['timezoneId']

You simply never imported the geonames module.  Somewhere before your 
first line of code, you want to add:

import geonames

This assumes that you've saved the module in a file named "geonames.py".



More information about the Python-list mailing list