retry in try:...except:

Mark Pilgrim f8dy at my-deja.com
Mon Feb 12 00:03:12 CET 2001


In article <UDCh6.101352$Pm2.1931128 at news20.bellglobal.com>,
  dan at eevolved.com wrote:
> Does something like this exist
>
> def getval(self, key)
>         try:
>                 return self.__keys[key]
>         except KeyError:
>                 self.__keys[key] = None
>                 retry #!!!!
>
> thanks,
> Dan

def getval(self, key): return self.__keys.setdefault(key, None)

## For more information about the setdefault method, see
http://python.org/doc/current/lib/typesmapping.html

-M
--
You're smart; why haven't you learned Python yet?  http://diveintopython.org/


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list