|
Description:
|
|
Watch the live stream:
Watch on YouTube
About the show
Sponsored by Datadog: pythonbytes.fm/datadog
Michael #1: Physics Breakthrough as AI Successfully Controls Plasma in Nuclear Fusion Experiment
- Interesting break through using AI
- Is Python at the center of it?
- With enough digging, the anwswer is yes, and we love it!
Brian #2: PEP 680 -- tomllib: Support for Parsing TOML in the Standard Library
- Accepted for Python 3.11
- This PEP proposes basing the standard library support for reading TOML on the third-party library tomli
Michael #3: Thread local
threading.local: A class that represents thread-local data. Thread-local data are data whose values are thread specific.
- Just create an instance of
local (or a subclass) and store attributes on it
- You can even subclass it.
Brian #4: What is a generator function?
- Trey Hunner
- Super handy, and way easier than you think, if you’ve never written your own.
- Really, it’s just a function that uses
yield instead of return and supplies one element at a time instead of returning a list or dict or tuple or other large structure.
- Some details
- generator functions return generator objects
- generator objects are on pause and use the built in
next() function to get next item.
- they raise
StopIteration when done.
- Most generally used from
for loops.
- Generator objects cannot be re-used when exhausted
- but you can get a new one with the next
for loop you use. So, it’s all good.
Michael #5: dirty-equals
- via Will McGugan, by Samual Colvin
- Doing dirty (but extremely useful) things with equals.
from dirty_equals import IsPositive
assert 1 == IsPositive
assert -2 == IsPositive # this will fail!
user_data = db_conn.fetchrow('select * from users')
assert user_data == {
'id': IsPositiveInt,
'username': 'samuelcolvin',
'avatar_file': IsStr(regex=r'/[a-z0-9\-]{10}/example\.png'),
'settings_json': IsJson({'theme': 'dark', 'language': 'en'}),
'created_ts': IsNow(delta=3),
}
Brian #6: Commitizen
Extras:
- pytest book
- 40% off sale continues through March 19 for eBook
- Amazon lists the book as “shipping in 1-2 days”, as of March 2
Michael:
>>> x = "abcdefg"
>>> x.startswith(("ab", "cd", "ef"), 2)
True
Joke: CS Background |