Hi Alex,
Le 03/10/2015 16:52, Alex Glaros a écrit :
> Can someone please tell me what is wrong with syntax?
>
> Below is result of API data from geoNames.org
>
> location_data =
>
> |
> {u'postalcodes':[{u'placeName':u'Del
> Pante\xf3n',u'countryCode':u'MX',u'adminName3':u'Juan Rodr\xedguez
> Clara',u'lat':19.853749999999998,u'postalcode':u'95694',u'lng':-97.16653,u'adminName1':u'Veracruz
> de Ignacio de la Llave',u'adminName2':u'Juan Rodr\xedguez
> Clara',u'adminCode1':u'VER',u'adminCode2':u'094',u'adminCode3':u'27'},{u'placeName':u'Feliciano
> Ceballos',u'countryCode':u'MX',u'adminName3':u'Juan Rodr\xedguez
> Clara',u'lat':19.853749999999998,u'postalcode':u'95694',u'lng':-97.16653,u'adminName1':u'Veracruz
> de Ignacio de la Llave',u'adminName2':u'Juan Rodr\xedguez
> Clara',u'adminCode1':u'VER',u'adminCode2':u'094',u'adminCode3':u'27'},{u'placeName':u'La
> Bomba',u'countryCode':u'MX',u'adminName3':u'Juan Rodr\xedguez
> Clara',u'lat':19.43944,u'postalcode':u'95694',u'lng':-96.81416999999999,u'adminName1':u'Veracruz
> de Ignacio de la Llave',u'adminName2':u'Juan Rodr\xedguez
> Clara',u'adminCode1':u'VER',u'adminCode2':u'094',u'adminCode3':u'27'},{u'placeName':u'Las
> Mercedes',u'countryCode':u'MX',u'adminName3':u'Juan Rodr\xedguez
> Clara',u'lat':20.26806,u'postalcode':u'95694',u'lng':-97.51889,u'adminName1':u'Veracruz
> de Ignacio de la Llave',u'adminName2':u'Juan Rodr\xedguez
> Clara',u'adminCode1':u'VER',u'adminCode2':u'094',u'adminCode3':u'27'},{u'placeName':u'Mehlmeisel',u'countryCode':u'DE',u'adminName3':u'Bayreuth',u'lat':49.9667,u'postalcode':u'95694',u'lng':11.85,u'adminName1':u'Bayern',u'adminName2':u'Oberfranken',u'adminCode1':u'BY',u'adminCode2':u'094',u'adminCode3':u'09472'},{u'placeName':u'Winters',u'countryCode':u'US',u'lat':38.5322,u'postalcode':u'95694',u'lng':-121.9676,u'adminName2':u'Yolo',u'adminCode1':u'CA',u'adminCode2':u'113',u'adminName1':u'California'}]}
> |
>
> When I run this
>
> |
> your_country =(db.Country.countryCode ==location_data['countryCode'])
> |
>
> I get
>
>
> <type 'exceptions.KeyError'> 'countryCode'
>
> your_country = (db.Country.countryCode ==
> location_data['countryCode'])KeyError: 'countryCode'
If I get it right you should access it with :
location_data['postalcodes'][1]['countryCode']
>
> Can someone type this into their controller and show me the syntax for
> manipulating individual items so I can see the syntax? E.g.,
>
> location_data = {u'postalcodes': [{u'placeName': u'Del
> Pante\xf3n', u'countryCode': u'MX', u'adminName3': u'Juan
> Rodr\xedguez
> Clara', u'lat': 19.853749999999998, u'postalcode': u'95694', u'lng':
> -97.16653, u'adminName1': u'Veracruz
> de Ignacio de la Llave', u'adminName2': u'Juan Rodr\xedguez
> Clara', u'adminCode1': u'VER', u'adminCode2': u'094', u'adminCode3':
> u'27'}]}
>
> your_country = location_data['countryCode']
>
Have a look at this : http://sthurlow.com/python/lesson06/
Good luck,
--
“One original thought is worth a thousand mindless quotings.”
“Le vrai n'est pas plus sûr que le probable.”
Diogene Laerce
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
signature.asc
Description: OpenPGP digital signature

