Mexican States and Municipalities in Python

Mexican States and Municipalities in Python

First of all, I want to say I am using a creative commons image with this post, it is from Christian Frausto Bernal go check his pictures, they are pretty good.

Ok, so today I needed to get the mexican states and municipalities to use in some Plone dictionaries, so I got that from the SEPOMEX site.

I processed it a little and I got a very simple python file.

I has two dictionaries, the first one called states has a dictionary of normalized id’s and names, for example:

?View Code PYTHON
from states import states
print states['distrito_federal']

and you’ll get something like:

Distrito Federal

The other dictionary is the one with the municipalities, you can use it like this:

?View Code PYTHON
from states import data
print data['distrito_federal']['miguel_hidalgo']

And you should get something like Miguel Hidalgo.

Of your you can traverse it with something like:

?View Code PYTHON
for m in data['distrito_federal'].keys():
    print m

That way you can get every municipality key.

And of course you know.. it’s python and it should be pretty simple to convert it to mysql, csv, or another format you might be using..

So have fun!

If you think that might be helpful you can download it here:

Mexican States and Municipalities

About the Author

I'm a developer, mostly interested in Computer Science. Favorite languages: C, ObjC and Python. Hobbies: Music. Favorite Games: Assassin's Creed II, MGS Series