Re: [Tutor] How to control the not existent keys in a dict

2009-05-11 Thread Emilio Casbas
Thanks to all for the responses. Problem solved!, and I get a lot of valuable info. Thanks Emilio - Mensaje original > De: Alan Gauld > Para: tutor@python.org > Enviado: lunes, 11 de mayo, 2009 1:59:32 > Asunto: Re: [Tutor] How to control the not existent ke

Re: [Tutor] How to control the not existent keys in a dict

2009-05-10 Thread Richard Lovely
2009/5/10 Emilio Casbas : > > Hello, > > I have some problems testing keys not existent in a dictionary. > The code works testing existent keys with his corresponding value, but > If I enter a not existent key, an exception is raised. > How can I control the not existent key and assign him a defaul

Re: [Tutor] How to control the not existent keys in a dict

2009-05-10 Thread Alan Gauld
"Emilio Casbas" wrote If I enter a not existent key, an exception is raised. How can I control the not existent key and assign him a default value? One way is to use the get() method of a dictionary: d = {'Exists': True} d['Exists'] True d['Error'] Traceback!!! d.get('Error',Fal

Re: [Tutor] How to control the not existent keys in a dict

2009-05-10 Thread Emile van Sebille
On 5/10/2009 3:48 PM Emilio Casbas said... Hello, I have some problems testing keys not existent in a dictionary. The code works testing existent keys with his corresponding value, but If I enter a not existent key, an exception is raised. How can I control the not existent key and assign him a

[Tutor] How to control the not existent keys in a dict

2009-05-10 Thread Emilio Casbas
Hello, I have some problems testing keys not existent in a dictionary. The code works testing existent keys with his corresponding value, but If I enter a not existent key, an exception is raised. How can I control the not existent key and assign him a default value? u...@cipher:~/project/progra