What would be the best way of storing a python list of numbers (such as [4, 7, 10, 39, 91]) to a database? I am using the Pyramid framework with SQLAlchemy to communicate to a database.
Thanks!
Well conceptually you can store a list as a bunch of rows in a table using a one-to-many relation, or you can focus on how to store a list in a particular database backend. For example postgres can store an array in a particular cell using the sqlalchemy.dialects.postgres.ARRAY data type which can serialize a python array into a postgres array column.
Use string(Varchar). From Zen of Python: "Simple is better than complex."
sqlalchemy.types.PickleType can store list
来源:https://stackoverflow.com/questions/6222381/the-best-way-to-store-a-python-list-to-a-database