Trey Hunner
banner
trey.io
Trey Hunner
@trey.io
Python & Django team trainer

I help folks sharpen their Python skills with https://PythonMorsels.com 🐍🍪

YIMBY. 95% vegan.
When your UI makes a user think "eh there's a 75% chance that this is the right button", something has gone wrong.
February 12, 2026 at 1:52 AM
Python Tip #42 (of 365):

Avoid manually merging dictionaries. Use "a | b" instead. 🧵

Let's say you have 2 dictionaries:

context = {"language": "en", "timezone": "UTC"}
more_context = {"title": "Home", "breadcrumbs": ["Home"]}

And you'd like to merge them together...

#Python #DailyPythonTip
February 11, 2026 at 11:45 PM
New screencast on the lack of switch-case in #Python.

Instead of reaching for match-case as a switch-case replacement, I'd recommend using a dictionary.

Also see today's #DailyPythonTip on replacing if-elif chains with dictionaries.
Need switch-case in Python? It's not match-case!
Python's match-case is not a switch-case statement. If you need switch-case, you can often use a dictionary instead.
pym.dev
February 10, 2026 at 11:45 PM
Python Tip #41 (of 365):

Consider using dictionaries to replace if-elif chains. 🧵

#Python #DailyPythonTip
February 10, 2026 at 6:07 PM
Python Tip #40 (of 365):

Use dictionaries for grouping items (by using a dictionary of lists, sets, or other data structures). 🧵

This week's tips are all about dictionaries.

#Python #DailyPythonTip
February 9, 2026 at 11:45 PM
Python Tip #37 (of 365):

Avoid overusing the term "method". 🧵

In Python, the words "function" and "method" are not interchangeable.

All methods are functions, but not all functions are methods.

#Python #DailyPythonTip
February 8, 2026 at 7:04 PM
Python Tip #36 (of 365):

When accepting any number of objects to a function, consider when to accept an iterable and when to use * instead. 🧵

#Python #DailyPythonTip
February 7, 2026 at 7:04 PM
Python Tip #37 (of 365):

If you're missing function overloading from another programming language, try default argument values as an alternative. 🧵

Default arguments are not a full replacement for function overloading, but they can often be used to reach a similar end.

#Python #DailyPythonTip
February 6, 2026 at 7:04 PM
Python Tip #36 (of 365):

Instead of assigning a lambda function to a variable, use a "def" statement. 🧵

Instead of this:
square = lambda n: n**2

Write this:
def square(n): return n**2

#Python #DailyPythonTip
February 5, 2026 at 7:04 PM
Python Tip #35 (of 365):

When calling "functions", think in terms of "callables". 🧵

Most Python programmers occasionally use the word "function" to describe a class.

So when you see the word "function", unless we're talking about a function definiton, think "callable".

#Python #DailyPythonTip
February 4, 2026 at 7:04 PM
New screencast on where we play "the class or function game".

This is a game I often play with my students to demonstrate that the word "function" is a bit fuzzy in the #Python world.
Is it a class or a function?
If a callable feels like a function, we often call it a function... even when it's not!
pym.dev
February 4, 2026 at 12:15 AM
Reposted by Trey Hunner
Folks, have you been overwhelmed by ~All This~ and wanting a gentle compassionate space to think about agentic coding??

Good news: if you're in SF & have free time tomorrow afternoon you can come hang out with me and @anthrocypher.bsky.social in a popup casual learning event ❤️

luma.com/rdw3dq4h
Claude Code (Cr)afternoon · Luma
Have you seen people rave about Claude Code, and wondered whether agent-assisted coding is for you? We're people who both work in and around software teams,…
luma.com
February 3, 2026 at 11:32 PM
Python Tip #34 (of 365):

Remember that in Python, functions are objects. 🧵

If you need to call a bit of code later, you don't need to make a class with a method... you could just make a function!

#Python #DailyPythonTip
February 3, 2026 at 11:07 PM
Python Tip #33 (of 365):

Don't sleep on Python's keyword arguments / named arguments. 🧵

When you have the choice between a positional argument or a keyword argument, choose a keyword argument if it clarifies the argument's purpose.

#Python #DailyPythonTip
February 2, 2026 at 7:04 PM
Python Tip #32 (of 365):

When processing potentially large untrusted files, don't iterate over them. 🧵

#Python #DailyPythonTip
February 1, 2026 at 7:04 PM
Python Tip #31 (of 365):

If you need to preserve the original line endings when reading or writing a file, use newline="" when opening your file. 🧵

#Python #DailyPythonTip
January 31, 2026 at 7:04 PM
Python Tip #30 (of 365):

Consider file modes outside of read and write: you may (very occasionally) want a different mode. 🧵

#Python #DailyPythonTip
January 30, 2026 at 7:04 PM
Python Tip #29 (of 365):

When processing small files line-by-line, just read the whole thing into memory. 🧵

Reading files line-by-line with a "for" loop is a good practice for files that could be large, but for small files I would recommend reading the whole file at once.

#Python #DailyPythonTip
January 29, 2026 at 10:42 PM
Python Tip #28 (of 365):

Read large files line-by-line by looping over them. 🧵

If you are working with a file that could be very large (such as a log file that could be gigabytes in size), don't read the whole file all at once.

#Python #DailyPythonTip
January 28, 2026 at 7:04 PM
New screencast about how all iteration is the same in Python.

In #Python (largely thanks to our embrace of duck typing), looping is looping.
All iteration is the same in Python
YouTube video by Python Morsels
youtu.be
January 28, 2026 at 12:13 AM
Checking whether iterables are equal in Python: https://trey.io/0frqkp

#Python
January 27, 2026 at 11:44 PM
I just added quiz questions to my introductory Python course, Python Jumpstart... a feature I wish I'd had on day 1!

All existing users will now see 64 quiz questions in Jumpstart.

In total, Jumpstart includes 60 instructional videos, 64 quizzes, & 48 exercises. It's now VERY hands-on.
Python Jumpstart
An exercise-first introduction to Python in bite-sized chunks. Each section consists of many 4 minute videos, each followed by 30 minute exercises. By the end of this course you'll have a solid founda...
pym.dev
January 27, 2026 at 11:18 PM
Python Tip #27 (of 365):

Consider printing to files instead of writing. 🧵

If you're converting objects to strings to write them to a file, I'd use print() instead.

And if you're putting newlines in string literals in your write() calls, I'd consider switching to print().

#Python #DailyPythonTip
January 27, 2026 at 7:04 PM
Often there's a better way to write your code than using break in a loop. Read more ‘‰ https://trey.io/xtql6h #Python
trey.io
January 27, 2026 at 1:19 AM
You should implement dunder methods on your objects, but you shouldn't call dunder methods on other objects. Read more ‘‰ https://trey.io/p0h32w #Python
January 26, 2026 at 10:19 PM