Сериализуйте эти данные, используя pickle.dumps , и передайте их в поле BLOB вашей базы данных. Затем используйте pickle.loads()
для десериализации сохраненных данных.
Пример:
import pickle
import MySQLdb
## Pickle the list into a string
face_pickled_data = pickle.dumps(face_encoding)
## Connect to the database
connection = MySQLdb.connect('localhost','user','pass','myDatabase')
## Create a cursor for interacting
cursor = connection.cursor()
## Add the information to the database table
cursor.execute("""INSERT INTO faces VALUES (NULL, 'faceName', %s)""", (face_pickled_data, ))
## Select what we just added
cursor.execute("""SELECT data FROM faces WHERE name = 'faceName'""")
## Dump the results to a string
rows = cursor.fetchall()
## Get the results
for each in rows:
## The result is also in a tuple
for face_stored_pickled_data in each:
face_data = pickle.loads(face_stored_pickled_data)