Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

A microlibrary for handling exceptions

Project description

A microlibrary for handling exceptions.


from try_default import try_default

foo = []
result = try_default(lambda: foo[0], {IndexError: 'n/a'})
# result: 'n/a'

foo = ['spam']
result = try_default(lambda: foo[0], {IndexError: 'n/a'})
# result: 'spam'

bar = {'egg': foo[0]}
result = try_default(lambda: bar['spam'], {IndexError: 'n/a'})
# Raises KeyError

Project details

Release history Release notifications

This version
History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
try_default-1.2.tar.gz (1.9 kB) Copy SHA256 hash SHA256 Source None Mar 20, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page