exceptions

Jeff Epler jepler at unpythonic.net
Mon May 31 08:10:18 EDT 2004


Use "pass" as the body of the "except:" block.  For example:

    def put(s, i, j):
        """Store j at s[i], or do nothing if s is not that long"""
        try:
            s[i] = j
        except IndexError:
            pass

>>> l = [1, 2, 3]
>>> put(l, 1, "hi")
>>> put(l, 4, "bye")
>>> l
[1, 'hi', 3]

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20040531/1c63b451/attachment.sig>


More information about the Python-list mailing list