Elektrine
Log in Register
Paige Chat Timeline Gallery Friends Email Drive DNS Private DNS Domains VPN Kairo Nerve
Remote

Trey Hunner 🐍

@treyhunner@mastodon.social
mastodon 4.8.0-nightly.2026-10-06
  • Open on mastodon.social

#Python & #Django educator & team trainer

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

#pythonoddity

Also: ostrovegan, sentientist, YIMBY, and I think economics is highly underrated. I don't post about any of those topics very often.

he/him

0 Followers
0 Following
50 Posts
Joined June 04, 2022
💌 My Weekly Newsletter:
https://pym.dev/newsletter
🐍 Python Exercises:
https://www.pythonmorsels.com
📺 YouTube:
https://www.youtube.com/@PythonMorsels
🕸 Personal Blog:
https://treyhunner.com
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 2mo ago
Did you know that map()/filter() were added to Python 6 years before comprehensions? Also range() was added 9 years before zip() which was added 3 years before enumerate(). And strings methods weren't methods for the first 9 years... they lived in the string module! For years I've wanted an easier way to look up facts like those. Now I have a way! https://pym.dev/since It's also available as a CLI tool via PyPI uvx sincewhen 'sum()' #Python #programming
pym.dev
12
0
9
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 2mo ago
Replying to
I find that I appreciate truthiness when it feels like we're asking "does this exist". I think of this question in the case of the hours example above but not for the remainder of division by 2. If you avoid truthiness for numbers altogether, I wouldn't blame you. I rely on truthiness checks heavily for checking non-emptiness and non-noneness, but I rarely use them for checking non-zeroness. It CAN be handy, but I do sometimes find it less readable. 🧵 (2/2)
5
1
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago

I made a thing last week and Earth Day seems like a great day to announce it. 🌏

https://Whereabouts.Earth is a fun (for me at least) app for learning the location of every country on Earth.

It uses a very effective learning technique (spaced repetition), but you don't need to know how that part works. It will work.

My geography knowledge has improved a LOT over the past week.

Join me in learning about the only home we'll ever have.

(And please share your feedback if you actually use this)

whereabouts.earth
23
12
14
1
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago

T-strings are primarily useful for the maintainers of libraries that are used by other Python developers.

Read more 👉 https://trey.io/n4mlgb

#Python

trey.io
14
0
9
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 6mo ago

Python Tip #99 (of 365):

Don't convert pathlib.Path objects to strings

Using a pathlib.Path object in an f-string or a print call is fine and I do this often.

But if you THINK you need to convert a pathlib.Path object to a string to pass it off to some other path-handling utility, you probably don't need to. Most path-handling utilities in Python support pathlib.Path objects just fine.

#Python #DailyPythonTip

mastodon.social

Mastodon

13
0
5
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago

Python Tip #106 (of 365):

Name ambiguous unicode characters with "\N{...}"

When you need to represent a non-ASCII character, you can either:

1. Copy-paste the character directly into your file
2. Use a "\u" or "\U" prefix to represent the character by its code point
3. Use "\N" to represent the character by its name

🧵 (1/3)

#Python #DailyPythonTip

mastodon.social

Mastodon

11
0
6
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 6mo ago

Python Tip #97 (of 365):

When you need to read/write a whole file all at once, use the appropriate pathlib.Path helper method

Instead of:

with open(path) as file:
contents = file.‍read()

Do this:

contents = path.‍read_text()

And instead of:

with open(path, mode="wt") as file:
file.write(contents)

Do this:

path.write_text(contents)

#Python #DailyPythonTip

mastodon.social

Mastodon

11
0
3
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 6mo ago

RE: @pycon@fosstodon.org

This is a magical moment for me... the Cabo card game has been mentioned in a PyCon promo post!

I've been teaching people Cabo since my first PyCon US and I've met SO many people from spreading this card game during PyCon.

I very much look forward to teaching Cabo (and watching others teach it I hope) at #PyConUS this year.

fosstodon.org
11
0
2
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 6mo ago

$ docker volume prune
...
Total reclaimed space: 224.4GB

Yikes...

9
2
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago

Python Tip #118 (of 365):

Instead of argparse.FileType, use pathlib.Path

The argparse module's FileType is deprecated (as of Python 3.14).

It has known issues: no newline argument accepted, encourages not using a context manager, etc.

Instead of argparse.FileType you should use pathlib.Path.

Using "type=Path" will auto-convert given arguments to pathlib.Path objects.

That way all command-line-provided file paths will turn into pathlib.Path objects automatically!

#Python #DailyPythonTip

mastodon.social

Mastodon

7
0
3
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago

RE: @ThePSF@fosstodon.org

Stay at The Westin and play Cabo and other card games and board games in the lobby in the evenings!

All are welcome to join. You'll be able to spot us because we'll look like PyCon attendees. Come over, say hi, play games, and chat.

fosstodon.org

Python Software Foundation: "Are you going to #PyConUS? Have you booked in our…" - Fosstodon

7
0
5
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago

RE: @hugovk@mastodon.social

Big news (for me at least): pprint on Python 3.15 is going to allow MUCH friendlier output! 🎉

Instead of:

pprint.pprint(some_object)

If you do this:

pprint.pprint(some_object, indent=4, expand=True)

You'll see output that looks like the most commonly used modern Python line-wrapping style in actual code!

I rarely use pprint because its output style is so bizarre.

I may start using it on Python 3.15 (even though the version I'll want to use will take 23 extra characters to type).

mastodon.social
7
0
3
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 6mo ago

Python Tip #100 (of 365):

Prefer the pathlib.Path object's is_file() and is_dir() methods over exists()

The exists method tells you SOMETHING is there but not WHAT.

Using is_file() or is_dir() is more explicit about what you're actually checking for, and usually what you actually want.

Usually when I find myself using exists(), I'll realize that I wanted one of the more specific methods instead.

#Python #DailyPythonTip

mastodon.social

Mastodon

7
1
5
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago

RE: @pycon@fosstodon.org

Coming to #PyConUS? Register for my tutorial to learn about generators & iterators with me.

See you there!

fosstodon.org
5
0
3
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago
Replying to
If you want to more deeply customize the message shown to the user, you can raise an argparse.ArgumentTypeError instead of a ValueError: def date(string): try: return dt.‍date.fromisoformat(string) except ValueError: message = "invalid YYYY-MM-DD date: {string!r}" raise argparse.ArgumentTypeError(message) from None If we had raised a ValueError, the printed message will be prefixed with "argument date: ". Not so bad, but sometimes unwanted. 🧵 (3/3)
5
1
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 6mo ago

Have a date string and want to find the format string needed to parse it?

Read more 👉 https://trey.io/l4b84k

#Python

trey.io
5
1
2
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago

Python Tip #105 (of 365):

When breaking a function call or list literal over multiple lines, use trailing commas.

For example, take this list:

fruits = [
"lemons",
"apples",
"watermelon",
]

Moving "lemons" to the end is easy when there's a trailing comma: just cut and paste.

Without trailing commas, moving "lemons" to the end means adding a comma after "watermelon" AND removing one after lemons.

🧵 (1/2)

#Python #DailyPythonTip

mastodon.social

Mastodon

4
0
2
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago
Replying to
@a2_4am@mastodon.social @glyph@mastodon.social @brouhaha@mastodon.social @AlSweigart@mastodon.social I feel like there are now many more bits of Python syntax that the average user doesn't *really* need to know until they encounter it in the wild. the walrus operator, t-strings, match-case, exception groups, and I suspect the new lazy imports and sentinel utility will fall into this mental bucket for me as well. Those are all great features, but they're nice-to-haves for most users or even just for a minority of users.
3
2
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 6mo ago

I've updated my blog post on how to have a great first #PyConUS: https://trey.io/first-pycon

The only TBD links are the volunteering link and the open spaces links.

I'm considering making an audio recording of this post for folks to listen to during the travels to Long Beach. Anyone interested in that?

mastodon.social

Mastodon

4
0
2
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 6mo ago

Python Tip #98 (of 365):

Don't use open method on pathlib.Path objects 🧵

Instead of this:

with path.‍open() as file:
...

Prefer this:

with open(path) as file:
...

Since Python 3.6, pathlib.Path objects can be passed to the built-in open function.

pathlib.Path's open method is a relic from an earlier version of pathlib that wasn't yet fully embraced by Python's various path-handling features.

I recommend using Python's built-in open() function everywhere.

#Python #DailyPythonTip

mastodon.social

Mastodon

4
0
2
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago

Python Tip #104 (of 365):

Use an _ to represent a placeholder variable.

This can be handy when you need to use range to loop N times but you don't care about the current iteration number in the loop:

matrix = [[0] * 3 for _ in range(3)]

Or when you're unpacking a tuple and one or more tuple values are unimportant:

[(item, _)] = collections.Counter(items).most_common(1)

When I see _ I think "I don't need to care about that value".

#Python #DailyPythonTip

mastodon.social

Mastodon

3
0
1
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 6mo ago

@pythonbytes@fosstodon.org some interesting things you may want to consider in an upcoming episode:

1. Savannah Ostrowski's new Core Dispatch newsletter: https://coredispatch.xyz
2. my article on pdbrc files: https://treyhunner.com/2026/04/customizing-pdb-with-pdbrc/ or Ned's *much* earlier article that I discovered after I published mine: https://nedbatchelder.com/blog/200704/my_pdbrc
3. I can't remember whether you've covered this and it might not be time yet (it's only a draft PEP still) but I found the PEP on d-strings interesting: https://peps.python.org/pep-0822/

Core Dispatch
Core Dispatch

Core Dispatch

A regular digest of what

3
1
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago
Replying to
@glyph@mastodon.social @a2_4am@mastodon.social @brouhaha@mastodon.social @AlSweigart@mastodon.social not that I know of! Part of the problem is, especially with annotations, it depends on what you're looking for when you say "modern Python". I rarely use type annotations but when I do I try to embrace them wholeheartedly (which I find quite challenging at times, partly due to the slight battle between concrete types and duck typing). Also if you're making code that parses ASTs, match-case is amazing. If you're not, its many features aren't worth knowing.
2
6
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago
Replying to
@phildini@wandering.shop I see no reason why there shouldn't be games happening every night in EVERY hotel lobby!
2
0
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago
Replying to
And then you would use "type=date" in your parser.add_argument call to use that date function for parsing. Of course, in the specific example of parsing a date, you could specify "type=dt.‍date.fromisoformat" instead. But then parsing errors would show fromisoformat to the user: program: error: argument date: invalid fromisoformat value: '01/01/2025' And that's not the most user-friendly experience. 🧵 (2/3)
2
1
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago

Python Tip #108 (of 365):

Don't use semicolons.

Want to put 2 statements on one line?

from rich.traceback import install; install(show_locals=True)

Don't.

Just use 2 lines:

from rich.traceback import install
install(show_locals=True)

It's more readable.

That's the entirety of today's tip. 🤷

#Python #DailyPythonTip

mastodon.social

Mastodon

2
0
2
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago

Python Tip #107 (of 365):

Use the walrus operator to simplify "while" loops.

This generator function reads a file in chunks:

def read_in_chunks(path):
with open(path, mode="rb") as file:
chunk = file.‍read(8192)
while chunk:
yield chunk
chunk = file.‍read(8192)

Notice that "chunk = file.‍read(8192)" appears twice: once before the loop and once at the end.

This is a somewhat common pattern with "while" loops.

🧵 (1/2)

#Python #DailyPythonTip

mastodon.social

Mastodon

2
0
1
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago

“Parentheses are used for 3 things in Python: calling callables, creating empty tuples, and grouping.”

Read more 👉 https://pym.dev/unnecessary-parentheses/

#Python

pym.dev
2
0
1
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 6mo ago

“Every iterable-accepting class is a comprehension-like tool waiting to happen.”

Read more 👉 https://pym.dev/custom-comprehensions/

#Python

pym.dev
2
0
4
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 6mo ago
Replying to
@glyph yup! $ docker system prune -a ... Total reclaimed space: 18.79GB
2
2
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 6mo ago
Replying to
@ryancheley@mastodon.social 🫂 Thank you for sharing this Ryan. This is beautifully written.
2
0
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 4mo ago
Replying to
@judy2k@chaos.social thanks Mark! 😁❣️
1
1
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago
Replying to
@pathunstrom I see a "total" variable in your future as well 🔮😉
1
1
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago
Replying to
@philip@mastodon.mallegolhansen.com It isn't open source. I'm considering making a page that lists the tech it uses. It's pretty much MapLibre, Alpine.js, Tailwind, Python, Django, the fsrs Python library (for the space repetition algorithm), and some public geojson data for the various borders... also a bunch of code mess to work around specific cases where small countries were too zoomed in or not zoomed in enough and such.
1
0
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago
Replying to
@_KevinTrainor@mastodon.online Parts of it could certainly be made by Python beginners, but all of the heavy lifting in the UI is front in JavaScript & CSS. It's about 40% JS, 20% HTML, 40% Python/Django (not counting the 20% that's CSS but not we're at 120%).
1
1
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago
Replying to
@bengerman@hachyderm.io love it. Adding to the fix-at-some-point list. ✅
1
2
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago
Replying to
@frameadvance@mastodon.social thanks so much!
1
0
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago

“Python typically prints unhandled exceptions and warning messages to standard error.”

Read more 👉 https://pym.dev/standard-error/

#Python

pym.dev
1
0
1
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago

“But del is a statement, not a function.”

Read more 👉 https://pym.dev/unnecessary-parentheses/

#Python

pym.dev
1
0
1
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 6mo ago

“While splitting on a line feed character will often work, I recommend using the string splitlines method instead.”

Read more 👉 https://pym.dev/splitlines/

#Python

pym.dev
1
0
3
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 6mo ago
Replying to
I'm surprised at how well that came out. I'm VERY curious about the process that was used to make this. Something (or someone?) clearly removed the background from my avatar and there's some decent wrapping of text (which I hope holds up well for even longer titles). I tried generating one for my talk also, but it looks like both buttons go to the same image. Props to someone on the @pycon team for making such a fancy image!
1
0
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago
Replying to
@Yhg1s@social.coop 🤔 it sounds like I need a new "Former Yugoslavia" collection 💡
0
0
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago
Replying to
@frameadvance@mastodon.social ack I've hit that "sometimes the text box doesn't appear" issue. It happens for me about 1 in every 100 times it's supposed to appear and I was hoping I fixed it yesterday. How often are you seeing it? And is that Safari on an iOS device? Just FYI if it happens again: tap the map. That should bring up a "Keep going" or "Stop" prompt and if you click "Keep going" the input will appear again. At least that's worked for me each time. I'll see if I can figure it out. It's confusing!
0
4
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago
Replying to
@bengerman@hachyderm.io Interesting! Opening in issue now. Thanks!
0
0
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 6mo ago
Replying to
@simoncrowe yeah that was nearly half the space on my drive. I had been clearing old files away because my drive has been filling up recently. I realized today that my disk usage analyzer tool showed WAY less space used than actually made sense given the size of the drive and the available space... turns out I needed to run it with root access to see the mess that docker had been making.
0
0
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago
Replying to
@adamchainz@fosstodon.org 💗 learning IS a form of working... sort of.
0
0
0
0
Open post
Trey Hunner 🐍 @treyhunner@mastodon.social
· 5mo ago
Replying to
@Yhg1s@social.coop @frameadvance@mastodon.social good to know. I am at least able to reproduce this one on my own devices, so I'll troubleshoot and figure out a fix eventually.
0
0
0
0
Back
313k7r1n3
Elektrine

Tor hidden service

elekhj7afj4qnrr4yd3bkzslsyo5jgfxw3orgjkhlcxifueodybyiiad.onion

I2P eepsite

j6b6cyk6gjmepjih7jjadxgxvvf3lzzujljuu2v4biemzpg3naya.b32.i2p

Platform

  • Email
  • Chat
  • Timeline
  • VPN
  • DNS

Company

  • About
  • Contact
  • FAQ
  • Lite (no JS)

Legal

  • Terms of Service
  • Privacy Policy
  • Transparency Report
  • Report Abuse
  • Warrant Canary
  • VPN Policy

Support

  • support@elektrine.com
  • Report Security Issue
Mail client setup IMAP mail.elektrine.com:993 POP3 mail.elektrine.com:995 SMTP mail.elektrine.com:465
© 2026 Elektrine. All rights reserved. Server: 13:23:36 UTC