shove does not store data as expected

Alex metallourlante at gmail.com
Wed Apr 21 05:51:52 EDT 2010


Dear all,
I'm trying to use the shove module (http://pypi.python.org/pypi/shove)
for a simple script. The script read a CSV file ad store the data.
When I check the content of the "store" object (instance of Shove)
*before* I close it, the data are all there but when I close and re-
open it some data are lost. How it is possible? There is something
wrong in my code or I didn't understand how shove works?

Thanks in advance.

Here is a sample of my code:

DBNAME = "file://store.db"

    csv_file ="test.csv"
    cities = csv.reader(open(csv_file), delimiter=";")
    store = Shove(DBNAME, compress=True)
    for city,region,code in cities:
        entry_list = store.setdefault(region, [])
        data = 'just a sample'
        entry = {city:data}
        entry_list.append(entry)

    print "----Before closing----"
    for k,v in store.iteritems():
        print "Key->", k
        print "Value->", v
    print "----"
    store.close()

    store = Shove(DBNAME, compress=True)
    print "----After closing and re-opening----"
    for k,v in store.iteritems():
        print "Key->", k
        print "Value->", v
    print "----"

Here is the output

----Before closing----
Key-> Marche
Value-> [{'Ancona': 'just a sample'}, {'Ascoli Piceno': 'just a
sample'}]
Key-> Piemonte
Value-> [{'Alessandria': 'just a sample'}, {'Asti': 'just a sample'}]
Key-> Puglia
Value-> [{'Bari': 'just a sample'}, {'Barletta-Andria-Trani': 'just a
sample'}]
Key-> Valle d'Aosta
Value-> [{'Aosta': 'just a sample'}]
----
----After closing and re-opening----
Key-> Marche
Value-> [{'Ancona': 'just a sample'}]
Key-> Piemonte
Value-> [{'Alessandria': 'just a sample'}]
Key-> Puglia
Value-> [{'Bari': 'just a sample'}, {'Barletta-Andria-Trani': 'just a
sample'}]
Key-> Valle d'Aosta
Value-> [{'Aosta': 'just a sample'}]
----

Here is the content of the CSV file:

Alessandria;Piemonte;AL
Ancona;Marche;AN
Aosta;Valle d'Aosta;AO
Ascoli Piceno;Marche;AP
Asti;Piemonte;AT
Bari;Puglia;BA
Barletta-Andria-Trani;Puglia;BT




More information about the Python-list mailing list