Thanks to all for the responses. Problem solved!, and I get a lot of valuable info.
Thanks Emilio ----- Mensaje original ---- > De: Alan Gauld <[email protected]> > Para: [email protected] > Enviado: lunes, 11 de mayo, 2009 1:59:32 > Asunto: Re: [Tutor] How to control the not existent keys in a dict > > > "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',False) > False > > HTH, > > > -- Alan Gauld > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > > > > _______________________________________________ > Tutor maillist - [email protected] > http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
