Hi Guys!

I am trying to make a simple and very basic Database in Python. Something, like a small agenda with contacts.
I make a dictionary within the script and I was trying to update that info with new Input data. The problem is that I am not sure I can do it and second, I don't know if it would be better to update an "external" dictionary in another file. The code is in portuguese (below) but it's simple. It's just a simple dictionary with a Client's info. With...

 - Name;
 - Surname;
 - Address;
 - Zip/Postal Code;
 - City ;
 - Country;
 - Phone number

...etc, etc, 7 fields.

I want to update the info with new Clients input data.
Any help please?

Cliente = {}
Cliente['Nome'] = {}
Cliente['Apelido'] = {}
Cliente['Morada'] = {}
Cliente['Cod_Postal'] = {}
Cliente['Localidade/Cidade'] = {}
Cliente['Pais'] = {}
Cliente['Telefone'] = {}

def lookup(data, label, name):
    return data[label].get(name)


print '-----------------------------'
print 'Introduza os dados do Cliente '
print '-----------------------------'
print '_____________________________'
name = str(raw_input('Nome: '))
surname = str(raw_input('Sobrenome: '))
print '--------------------'
print '       Morada'
print '--------------------'
street = str(raw_input('Rua: '))
number = str(raw_input('Numero: '))
postal_code = str(raw_input('Codigo Postal: '))
city = str(raw_input('Cidade: '))
country = str(raw_input('Pais: '))
print '--------------------'
phone = str(raw_input('Telefone: '))
print '____________________'
print ''

address_1 = street+', '+number+','
address_2 = postal_code+' '+city.capitalize()+','
address_3 = country.capitalize()

a = name.capitalize()+' '+surname.capitalize()
print name.capitalize()+' '+surname.capitalize()
print address_1
print address_2
print address_3
print phone

Cliente = {
    'Antonio Camara':{
        'Morada':'Rua das Taipas, 9',
        'Cod_Postal':'2300-000 Porto',
        'Pais':'Portugal',
        'Telf':'221112345'
    }
}

x = {a:{'Morada':address_1,'Cod_Postal':address_3,'Pais':address_3,'Telf':phone}}
b = Cliente.update(x)
print b

Look into Python module shelve. It works like a dictionary for your data and saves all updates automatically as long as it is open.

Thank You! I'll check it out!

Did the shelve module work or do you still want to debug the dictionary class?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.