Skip to main content

try2

Simple wrapper for try-except blocks

Installation

pip install try2

Installation

pip install try2

Quickstart

from try2 import try2

def reciprocal(n):
    return 1 / n

ls = [1, 2, 0, 3, 0, 4]

for number in ls:
    x = try2(reciprocal, number, "bad")
    print(number, "=>", x)

# 1 => 1.0
# 2 => 0.5
# 0 => bad
# 3 => 0.3333333333333333
# 0 => bad
# 4 => 0.25

Why I wrote this

I needed a simply one-liner try-except function for many of my projects, and I found myself defining helper try-except functions everywhere, which got annoying quickly

But what if I need a more complex try-except wrapper?

If your wrapper gets any more complex than this, it's probably a good idea to write your own function

Release files for try2 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for try2 0.0.4
File Size Uploaded
try2-0.0.4.tar.gz 2.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for try2 0.0.4
File Interpreter ABI Platform
try2-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 4.5 kB

Release files / try2-0.0.4.tar.gz

Download URL try2-0.0.4.tar.gz
Size 2.3 kB
Tags Source
SHA-256 checksum
How to use checksums
68bb40667c111850f0b32c86387e1bf989a09c664dabcbea15a1b1bb346aa62b
BLAKE2b-256 checksum
How to use checksums
ddfc3fb532e75d00bcc43912f6881e95c5c1a3afe73eacbb64d126eb2bb453d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.3

Release files / try2-0.0.4-py3-none-any.whl

Download URL try2-0.0.4-py3-none-any.whl
Size 2.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
39df280b37fc1e246b464a76989de096fce605ebc629fc7b9ca1a7baac004b7c
BLAKE2b-256 checksum
How to use checksums
1873bc4fe70405d7fd0230591a695418f02ab31998272f1fadf103a432589e16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page