Brought to you by Michael and Brian - take a Talk Python course or get Brian's pytest book

#270: Can errors really be beautiful?

Published Thu, Feb 10, 2022, recorded Wed, Feb 9, 2022

Watch the live stream:

Watch this episode on YouTube
Play on YouTube
Watch the live stream replay

About the show

Sponsored by Datadog:

Special guest: Dean Langsam

Brian #1: A Better Pygame Mainloop

  • Glyph
  • Doing some game programming is a great way to work on coding for early devs (and experienced devs).
  • pygame is a popular package for writing games in Python
  • But… the normal example of a main loop, which listens for events and dispatches actions based on events, has some problems:
    • it’s got a while 1:
      • that wastes power, too much busy waiting
      • looks bad, due to “screen tearing” which is writing to a screen while your in the middle of drawing it
  • This post discusses the problems, and walks through to an async main loop that creates a better gaming experience.

Michael #2: awesome sqlalchemy

Dean #3: ThreadPoolExecutor in Python: The Complete Guide

  • Long, but worth it (80-120 minutes). Could be consumed in parts. It’s mostly a collection of other blogposts on superfastpython
  • Many examples
  • LifeCycle
  • Usage patterns
    • Map and was
    • as_completed vs sequentially
    • callbacks
  • IO-Bound vs CPU-bound
  • Common Questions
  • Comparison
    • vs. ProcessPoolExecutor
    • vs. threading.Thread
    • vs. AsyncIO

Brian #4: Chaining comparison operators

  • Rodrigo Girão Serrão
  • I use chained expressions all the time, mostly with ranges:
    • min <= x <= max, which is like (min <=x) and (x <= max)
  • There are lots of chained expressions available, and some not so obvious.
  • a == b == c
    • all are equal, no prob
  • what abut a != b != c ?
    • This actually can return True if a == c
  • Lots of other issues with chaining discussed in the article, like non-constant expressions and side effects

Michael #5: Create Beautiful Tracebacks with Python’s Exception Hooks

    def exception_hook(exc_type, exc_value, tb):

    sys.excepthook = exception_hook

Dean#6: Ways I Use Testing as a Data Scientist

  • The importance of knowing what to test for
  • using assert in code on ad-hoc things. Do it while coding.
  • Us numpy np.isclose to test “almost equal” on entire arrays. also [assert_frame_equal](
  • Use hypothesis for bombarding the function with smart tests.
  • Pandera and Great Expectations
  • tests are documentation!
  • Work with Arrange-Act-Assert
  • Even if we’re not sure what to assert, writing a test that executes the code is still valuable.




Joke: Spelling

Want to go deeper? Check our projects