Python Bytes is a weekly podcast hosted by Michael Kennedy and Brian Okken. The show is a short discussion on the headlines and noteworthy news in the Python, developer, and data science space.
#270 Can errors really be beautiful?
February 10, 2022
00:47:25
41.74 MB
Downloads: 0
Watch the live stream:
Watch on YouTubeAbout the show
Sponsored by Datadog: pythonbytes.fm/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
- it’s got a
- This post discusses the problems, and walks through to an async main loop that creates a better gaming experience.
Michael #2: awesome sqlalchemy
- A few notable ones
- SQLAlchemy-Continuum: Versioning and auditing extension for SQLAlchemy.
- SQLAlchemy-Utc: SQLAlchemy type to store aware
datetime.datetime
values. - SQLAlchemy-Utils: Various utility functions, new data types and helpers for SQLAlchemy
- filedepot: DEPOT is a framework for easily storing and serving files in web applications.
- SQLAlchemy-ImageAttach: SQLAlchemy-ImageAttach is a SQLAlchemy extension for attaching images to entity objects.
- SQLAlchemy-Searchable: Full-text searchable models for SQLAlchemy.
- sqlalchemy_schemadisplay: This module generates images from SQLAlchemy models.
- Can we also get a shoutout to SQLModel?
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
ifa == c
- This actually can return
- 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](https://pandas.pydata.org/docs/reference/api/pandas.testing.assert_frame_equal.html)
- 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.
Extras
Dean:
- Deprecate urllib out of stdlib?
- IPython 8 is out
- It’s less code!
- 37,500 LOC across 348 files → 36,100 across 294 files “I’m sorry I wrote you such a long letter. I didn’t have time to write you a short one.” – Blaise Pascal
- This was all done thanks to a developer hired through Small Development Grants
- coloring exceptions
- It’s less code!
Michael:
- Python Shorts New videos
/
on pypi.org
Joke: Spelling