No hay duda de que esto se debe hacer usando una base de datos, en lugar de pickle, las bases de datos están diseñadas exactamente para este tipo de problema.
Aquí hay un código para comenzar, que coloca un diccionario en una base de datos sqllite y muestra un ejemplo de cómo recuperar un valor. Para que esto funcione con tu diccionario real en lugar de mi ejemplo de juguete, necesitarás aprender más sobre SQL, pero afortunadamente hay muchos recursos excelentes disponibles en línea. En particular, es posible que desee aprender a usar SQLAlchemy, que es un "Asignador relacional de objetos" que puede hacer que trabajar con bases de datos sea tan intuitivo como trabajar con objetos.
import os
import sqlite3
# an enormous dictionary too big to be stored in pickle
my_huge_dictionary = {"A": 1, "B": 2, "C": 3, "D": 4}
# create a database in the file my.db
conn = sqlite3.connect('my.db')
c = conn.cursor()
# Create table with two columns: k and v (for key and value). Here your key
# is assumed to be a string of length 10 or less, and your value is assumed
# to be an integer. I'm sure this is NOT the structure of your dictionary;
# you'll have to read into SQL data types
c.execute("""
create table dictionary (
k char[10] NOT NULL,
v integer NOT NULL,
PRIMARY KEY (k))
""")
# dump your enormous dictionary into a database. This will take a while for
# your large dictionary, but you should do it only once, and then in the future
# make changes to your database rather than to a pickled file.
for k, v in my_huge_dictionary.items():
c.execute("insert into dictionary VALUES ('%s', %d)" % (k, v))
# retrieve a value from the database
my_key = "A"
c.execute("select v from dictionary where k == '%s'" % my_key)
my_value = c.next()[0]
print my_value
¡Buena suerte!
¿Qué le parece una base de datos? http://docs.python.org/library/sqlite3.html – FogleBird
5 GB wow, ¿puedo preguntar qué estás intentando eliminar usando Pickle? – mouad
¿qué tipo de datos tienes? Estoy pensando en un [hdf5] (http://www.hdfgroup.org/HDF5/) archivo de datos – konus