Home

I want to see the traceback#

import traceback
import sys

try:
    do_stuff()
except Exception:
    print(traceback.format_exc())
    # or
    print(sys.exc_info()[2])

I want to have structs like in Go#

For this you can use dataclasses. These convert a class by annotation into a dataclass.

from dataclasses import dataclass

# Define a dataclass to hold the URIs and their expected status codes
@dataclass
class URI:
    uri: str
    want: int

test = URI(uri="https://www.nonexistentwebsite.com", want=404),
print(test.uri)
print(test.want)

Packaging a project#