Trey Hunner 🐍

@treyhunner
2.5K Followers
325 Following
4.4K Posts

#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

πŸ’Œ My Weekly Newsletterhttps://pym.dev/newsletter
🐍 Python Exerciseshttps://www.pythonmorsels.com
πŸ“Ί YouTubehttps://www.youtube.com/@PythonMorsels
πŸ•Έ Personal Bloghttps://treyhunner.com

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

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

Read more πŸ‘‰ https://trey.io/l4b84k

#Python

Converting a string to a datetime

The datetime.strptime class method can parse a date/time string into a datetime object.

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?

How to have a great first PyCon (updated for 2026)

You’ve decided to invest energy, money, and time away from your home so that you can go to your first PyCon. Now you want to make sure you …

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!

I just discovered a "Speaker Card" button on my PyCon dashboard page.

@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.

β€œ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

Why splitlines() instead of split("\n")?

To split text into lines in Python, use the splitlines() method, not the split() method.

@glyph yup!

$ docker system prune -a
...
Total reclaimed space: 18.79GB

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

Yikes...

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