Question:
How best* can I store and access fixed U.S. State attributes in my python program?
* the most reasonable combination of clear, maintainable, quick and idiomatic
Background info:
I’m creating a python/flask app that regularly accesses U.S. State attributes for various displays and sorting. An example of the attributes:
State: South Carolina
- Proper Name:
South Carolina - Abbreviation:
SC - url friendly slug:
south_carolina - Region:
southeast
Currently, I’m storing some of this information in dictionaries (SO question regarding this). However, it seem more unwieldy as more attributes are added.
Some options I’ve considered
- Adding more dictionaries
- Seems clumsy
- Use a database
- I’m new to databases. I’m happy to learn, but I’m not clear this is the best approach. Also, I’m concerned this would be overkill.
- Add a
StateClass- Seems a little inelegant to create 50
Stateobjects just to query a few attributes.
- Seems a little inelegant to create 50
Thanks very much for your time.
Edit: Added explanation of what best means.
I ended up using a database to solve this problem. I considered a bunch of options and it seems to be the most reasonable in terms of effort, complexity and long-term maintenance.
Trying to make some other solution solve my problem here would really only be a crude recreation of database functionality anyhow e.g. dictionaries on dictionaries on dictionaries…
For those wondering, on this particular Flask app I went with Flask-SQLAlchemy on top of a sqlite3 database.