Convert Latitude, Longitude To TimeZone

Roy Smith roy at
Sun Mar 31 17:09:14 CEST 2013

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

> I found a piece of code
> [
> ] which uses the function []
> 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 

> 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 "".

More information about the Python-list mailing list