Sign in

Trey Hunner

@trey.io
4K followers 216 following 2.2K posts

Python & Django team trainer I help folks sharpen their Python skills with PythonMorsels.com 🐍🍪 I also blog at treyhunner.com & run Whereabouts.Earth PSF Fellow. YIMBY. 95% vegan.

PostsRepliesMedia
Trey Hunner @trey.io · 08/08/2026
Apparently Claude users get 3 free credits to try "/code-review ultra". I spend 2 of my 3 free credits on the same PR and got the same results both times. I feel like each of these results were a review of Anthropic's code than of my own. 🤔
"Review failed.""Review failed."
2111
Trey Hunner @trey.io · 31/07/2026
Python Tip #212 (of 365): Use any() and all() to check a condition across every item in an iterable 🧵 This: any_negative = False for n in numbers: if n < 0: any_negative = True break Can be rewritten as this: any_negative = any(n < 0 for n in numbers) #Python #DailyPythonTip
all_good = True
for item in iterable:
    if not condition(item):
        all_good = False
        break

Can be rewritten as:

all_good = all(
    condition(item)
    for item in iterable
)

Also...

any_good = False
for item in iterable:
    if condition(item):
        any_good = True
        break

Can be rewritten as:

any_good = any(
    condition(item)
    for item in iterable
)
141
Trey Hunner @trey.io · 11/07/2026
New daily game I've been enjoying hankgreen.com/smush · Jul 11 852 pts · PERFECT 💯 · 2-day streak 🥞🥞🥞 🥞⭐🥞 🥞🥞🥞
110
Trey Hunner @trey.io · 26/06/2026
My closest match doesn't surprise me. I would have been very surprised if I was categorized as a "doomer".
010
Trey Hunner @trey.io · 13/05/2026
#PyConUS #Whereabouts
A map of the PyCon US 2026 convention center in Long Beach with 5 red pins on it
181
Trey Hunner @trey.io · 03/05/2026
I made it so that once I'm expected to remember the location of a country for over 3 weeks, Whereabouts.Earth will make a confetti explosion where the bits of confetti are made of the flags of the countries I now remember so well! 🎊🇦🇶 I've been having fun making features that bring me joy. 💖
180
Trey Hunner @trey.io · 25/04/2026
But I would recommend using functools.cached_property instead. With @cached_property the value is computed once, then cached as a regular attribute. The first access does the work. Every access after that is instant. pym.dev/p/2mjp9/
from functools import cached_property
from pathlib import Path

class FileStats:
    def __init__(self, filename):
        self.path = Path(filename)

    @cached_property
    def line_count(self):
        with open(self.path) as file:
            return sum(1 for line in file)
030
Trey Hunner @trey.io · 25/04/2026
You might be tempted to manually cache a computed value... pym.dev/p/229fd/
from pathlib import Path

class FileStats:
    def __init__(self, filename):
        self.path = Path(filename)

    @property
    def line_count(self):
        if not hasattr(self, "_line_count"):
            with open(self.path) as file:
                self._line_count = sum(1 for line in file)
        return self._line_count
120
Trey Hunner @trey.io · 25/04/2026
A @property recomputes its value every time it's accessed. That's fine for computing values that should stay synced each time the attribute is accessed. But if the computation is expensive, you might not want to redo it every time. pym.dev/p/24n3p/
from pathlib import Path

class FileStats:
    def __init__(self, filename):
        self.path = Path(filename)

    @property
    def line_count(self):
        with open(self.path) as file:
            return sum(1 for line in file)
120
Trey Hunner @trey.io · 23/04/2026
Announcing whereabouts.earth for the second time today, this time with a video for those who'd prefer to watch me use it than try it out. I've really been enjoying sharing this with folks today. Happy #EarthDay all! 🌍
0102
Trey Hunner @trey.io · 14/04/2026
I love playing games in hotel lobbies during @pycon.us. It's hard to think of someone as an unapproachable stranger when you've spent 20 minutes playing a game in a small group with them. I plan to play games in The Westin lobby during #PyConUS at least a couple nights. See you at The Westin?
5 tables and a bunch of chairs at a slightly snake-like bench in lobby of The Westin Long Beach, where board games will be played
1102
Trey Hunner @trey.io · 22/03/2026
A Magritte moment from @davepeck.org during the last talk of #PyCascades on t-strings
t"This is not a string"
291
Trey Hunner @trey.io · 21/03/2026
Some big ideas in @lukasz.langa.pl's keynote at #PyCascades this morning
The universe is great at forgetting stuffPython is a public goodYou shouldn't have to bear the burden of systemic changeI'm not a radical I just care about user agency
1112
Trey Hunner @trey.io · 23/02/2026
Python Tip #54 (of 365): Copy-paste your way into comprehensions. 🧵 Have a "for" loop that loops over one list to build up another? You can probably copy-paste your way from a loop into a comprehension. #Python #DailyPythonTip
110
Trey Hunner @trey.io · 12/02/2026
When your UI makes a user think "eh there's a 75% chance that this is the right button", something has gone wrong.
A box that says "Are you sure you want to cancel your appointment?" and the buttons are "Cancel Appointment" and "Save Appointment".
040
Trey Hunner @trey.io · 03/12/2025
Apparently I'm pretty consistent with what I talk about on Bluesky. 😅 ... also I use that 😅 emoji a lot My most-used words in 2025 were: 1. "python" (360×) 2. "code" (43×) 3. "function" (39×) 4. "pyconus" (36×) 5. "morsels" (35×) See which words you used the most here: anisota.net/harvest
A word cloud showing "python" much bigger than anything else
150
Trey Hunner @trey.io · 28/11/2025
Mara's ship from She-Ra and the Princesses of PowerDoctor Who's TARDISThe space ship from Octavia Butler's Dawn (it wasn't described in detail in the book and I don't think this rendering is right but that's what it supposedly is)Wayfarer from A Long Way to a Small Angry Planet
120
Trey Hunner @trey.io · 27/10/2025
Increased diversity in communities usually comes from active outreach work. PyCon's has a partially blinded talk selection processes. If 300 people submit talks and 294 are men, then 98% of talks will likely be from men. If 500 people submit talks and 394 are men, then ~79% will likely be by men.
A tweet from Jessica McKellar on May 30, 2016:
Hello from your @PyCon Diversity Chair. % PyCon talks by women: (2011: 1%), (2012: 7%), (2013: 15%), (2014/15: 33%), (2016: 40%). #pycon2016
181
Trey Hunner @trey.io · 23/10/2025
When you type code into the Python REPL, it will be colorized as you type it. Read more 👉 trey.io/flfwr9 #Python
021
Trey Hunner @trey.io · 14/10/2025
So when writing a file using Python's csv module, you're expected to always specify newline="" when opening the file you're writing to, to make sure that you don't accidentally double up your carriage returns on Windows. Read more 👉 trey.io/ca0qyn #Python
000
Trey Hunner @trey.io · 14/08/2025
In the 1960s, teleprinters used a carriage return (CR) to move the printhead back to the beginning of the line, and they used a line feed (LF) to move to the next line. Read more 👉 trey.io/ca0qyn #Python
131
Trey Hunner @trey.io · 04/07/2025
This is such a weird email to get from the Social Security Administration... 🙁
Email from the Social Security Administration: 

The Social Security Administration (SSA) is celebrating the passage of the One Big, Beautiful Bill, a landmark piece of legislation that delivers long-awaited tax relief to millions of older Americans.

The bill ensures that nearly 90% of Social Security beneficiaries will no longer pay federal income taxes on their benefits, providing meaningful and immediate relief to seniors who have spent a lifetime contributing to our nation's economy.

“This is a historic step forward for America’s seniors,” said Social Security Commissioner Frank Bisignano. “For nearly 90 years, Social Security has been a cornerstone of economic security for older Americans. By significantly reducing the tax burden on benefits, this legislation reaffirms President Trump’s promise to protect Social Security and helps ensure that seniors can better enjoy the retirement they’ve earned."

The new law includes a provision that eliminates federal income taxes on Social Security benefits for most beneficiaries, providing relief to individuals and couples. Additionally, it provides an enhanced deduction for taxpayers aged 65 and older, ensuring that retirees can keep more of what they have earned.

Social Security remains committed to providing timely, accurate information to the public and will continue working closely with federal partners to ensure beneficiaries understand how this legislation may affect them.
010
Trey Hunner @trey.io · 02/07/2025
But PEP8 (the official Python style guide) recommends putting binary operators (operators that go in between two values, like and and or) at the beginning of each line, for the sake of readability. Read more 👉 trey.io/f98u5c #Python
010
Trey Hunner @trey.io · 01/07/2025
Working with file paths in Python? (splitting, joining, navigating, etc.) Check out #Python's pathlib module. It's great for splitting/joining paths, finding files by filename patterns, renaming files, and more. pym.dev/pathlib-module
Table showing 10 path-related tasks, including a short pathlib snippet that performs that task, as well as example output. This is the cheat sheet table from https://pym.dev/pathlib-module/#cheat-sheet
170
Trey Hunner @trey.io · 14/06/2025
I decided to just quote the oath of office on mine. #NoKings
White poster board that reads "PRESERVE PROTECT & DEFEND the CONSTITUTION" in red, white (black outline), blue, and black
022
Trey Hunner @trey.io · 18/05/2025
Enjoyed this morning's #PyConUS keynote from @tfmfm.bsky.social & @geoffhing.bsky.social on a very important use for #Python. is.gd/tmppyconus
Geoff and Tom on stage
160
Trey Hunner @trey.io · 16/05/2025
Hello #PyConUS attendee who I have probably never met! If you would like to say hello, please message me while we're both in the same city together! I'm on Signal at trey.02. More contact details at trey.io/pycon Also I have Python Morsels stickers! I'd love to give you one. 🐍🍪
A sticker of an adorable green snake hugging a vegan chocolate chip cookie with the text "Python Morsels" below it.
042
Trey Hunner @trey.io · 16/05/2025
When chatting in the hallway at PyCon, try leaving a gap for someone else to join the conversation. #PyConUS
Hallway Track! 

The Pac-Man rule

When standing in a group of people, always leave room for 1 person to join your group.
032
Trey Hunner @trey.io · 16/05/2025
We're playing Cabo and other games in the Westin lobby. Come join us #PyConUS folks!
020
Trey Hunner @trey.io · 15/05/2025
Don't miss out on the rooftop track at #PyConUS this year! 🌳 There are a couple dozen of us out here eating lunch right now and I many folks will be hanging out here over the next few days of @pycon.us. The rooftop track is like the hallway track, but with a great view! 🖼️
Eugene, Marie, Simon, and Yngve sitting at a table chatting about weird and fun things only vaguely related to PyCon
070
Trey Hunner @trey.io · 27/04/2025
Hey #NBPy folks! 👋 I'm flying out tonight, so if you would like a Python Morsels sticker, hug, or a chat, find me today. I would love to say hey to you if we haven't met yet! If you would like a Python Morsels sticker today PLEASE ask me for one (or 10!). I brought so many! 🐍🍪😅
Sticker showing an adorable snake hugging a vegan chocolate chip cookie along with the words "Python Morsels"
181
Trey Hunner @trey.io · 22/04/2025
"There is perhaps no better demonstration of the folly of human conceits than this distant image of our tiny world. To me, it underscores our responsibility to deal more kindly with one another, and to preserve and cherish the pale blue dot, the only home we've ever known." -Carl Sagan #EarthDay
The 25th anniversary re-processing of the Pale Blue Dot photo of Earth, originally taken by Voyager 1 on Feb 14, 1990. It shows the Earth, as a pale blue dot just a few pixels wide, in a mote of dust suspended in a sunbeam.
061
Trey Hunner @trey.io · 07/02/2025
Well that was weird... DeepSeek R1 just thought for almost 8 minutes before starting to give me a response. 🤯 It used over 22,000 tokens just thinking about a response. 🤔
DeekSeek logo next to "Thought for 474 seconds" at the top of a DeepSeek chat response
000
Trey Hunner @trey.io · 30/11/2024
Each day, you'll watch a 4 minute video and then attempt to write Python code. ⌨ It's 2 hours of video, but about 20 hours of carefully crafted bite-sized exercises. 🍪 I just launched this course and it's 50% off, but only through Monday. 💸 pym.dev/courses/jumpstart/overview
000
Trey Hunner @trey.io · 20/11/2024
Comprehensions have their own scope: >>> n = 4 >>> squares = [n**2 for n in range(9)] >>> n 4 But loops do NOT have their own scope: >>> n = 4 >>> for n in squares: ... >>> n 81 This looks like a #PythonOddity, but there's a good reason. #Python trey.io/function-sco...
Code at https://trey.io/function-scope-oddity
2140
Trey Hunner @trey.io · 14/02/2024
This photo was captured 33 rotations ago today, 6 million km from the sun. "There is perhaps no better demonstration of the folly of human conceits than this distant image of our tiny world." —Carl Sagan Sagan's full quote from the Cosmos series: youtu.be/GO5FwsblpT8?... Happy #PaleBlueDot Day 💜
The Pale Blue Dot image: an image of Earth taken from the edge of our solar system by the Voyager 1 spacecraft of February 14, 1990. More at https://science.nasa.gov/resource/voyager-1s-pale-blue-dot/
020