When is an exception not an exception? Using warnings in Python

Reuven M. Lerner

Reuven M. Lerner

Teaching Python and data science around the world since 1995. Author of the books "Python Workout" and "Pandas Workout". Publisher of the "Better developers" newsletter. I spend each day trying to help people improve their Python skills.

    Abstract

    Python's warnings are exceptions — but they're also distinct from exceptions, and are both used and trapped differently. In this talk, I'll introduce warnings, how to raise, trap, and redirect them, and show you best practices for their use. Many experienced developers don't know that Python's warning system supports filtering and suppressing warnings quite flexibly, based on a variety of parameters. You can thus turn certain warnings into (potentially fatal) exceptions, or ignore them entirely -- or enjoy the default behavior, in which they appear on the screen. In addition to showing you how you can create and display warnings, I'll also show you how you can create your own, and (perhaps even more significantly) give examples of when they're appropriate.

    Description

    Video

    Location

    R1

    Date

    Day 2 • 13:25-13:55 (GMT+8)

    Language

    English talk

    Level

    Intermediate

    Category

    Python Core