Convert dictionary key to object name in Python

Question

I've got a dictionary whose keys are country names, and its values are an object of the class Country, which has several attributes (population, area, etc.). For example:

{"Chile":Country(17000000,124234,...)}

However, when I try to reach a country, I have to do my_dict[country_name].attribute. I don't want a dictionary, I just want objects, so I can access them like country_name.attribute. Can anyone help me in doing this?

Thanks!


Show source
| class   | python   | object   | dictionary   2017-10-04 23:10 0 Answers

Answers to Convert dictionary key to object name in Python ( 0 )

Leave a reply to - Convert dictionary key to object name in Python

◀ Go back