@treyhunner@mastodon.social
@treyhunner@mastodon.social avatar

treyhunner

@treyhunner@mastodon.social

#Python & #Django educator & team trainer

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

#pythonoddity

Also a #humanist #YIMBY who is attempting more ethical eating (#vegetarian, not yet #vegan) and thinks #economics is highly underrated, but I don't post about those topics very often.

he/him

This profile is from a federated server and may be incomplete. Browse more on the original instance.

treyhunner, (edited ) to random
@treyhunner@mastodon.social avatar

I have been using Ubuntu as my primary operating system since 2006.

If I decide to buy a Lenovo ThinkPad X1 Carbon with Linux pre-installed, should I pick Ubuntu or Fedora?

Please reply with your reasoning.

Also relevant: I've gone through two Dell XPS 13's and a System 76 laptop all with multiple years of warranties because I don't like to do my own tech support. So I likely won't be reinstalling my own OS or heavily customizing the core OS.

treyhunner, to python
@treyhunner@mastodon.social avatar

Personal education nitpick ⚠️

It's unhelpful to show beginners tuple unpacking can swap two variables.

a, b = b, a

It is neat, but it's also very rarely a good idea. Yes there are a few cases where it makes sense to swap the values of two variables, but it's quite rare. Whenever I see this fact taught, it's taught as if it's useful (rather than just a fun fact).

I may be needlessly grumpy with this nitpick, but I really think this trick is shown far more than it's warranted.

treyhunner, to Podcasts
@treyhunner@mastodon.social avatar

For those interested in and vaguely interested in US public policy, politics, and the justice system: listen to More Perfect by NPR.

Specifically, I recommend starting from the early episodes back in 2016.

https://www.npr.org/podcasts/481105292/more-perfect

These are well-produced and informative. It's a good mix of "candy" and "homework".

You can consider this your podcast recommendation. Patriotism means staying informed enough to help push your nation toward forward progress, right?

treyhunner, to python
@treyhunner@mastodon.social avatar

I often see my students use the split method with a single space character:

>>> x.split(" ")

Usually using the split method without any arguments is preferable:

>>> x.split()

Why?

Well, the default string delimiter for splitting in isn't "space" but "any amount of consecutive whitespace":

>>> x = "Python is
\tneat."
>>> print(x)
Python is
neat.
>>> x.split()
['Python', 'is', 'neat.']

Plus split without any delimiter strips whitespace from the ends of a string!

treyhunner, (edited ) to random
@treyhunner@mastodon.social avatar

Want to turn your code into an image?

It's super easy with pygments' ImageFormatter.

(the preview card that social media sites show for the linked pastebin tool atually uses this approach too!)

https://www.pythonmorsels.com/p/234g4/

treyhunner, to PyConUS
@treyhunner@mastodon.social avatar

PyCon friends and yet-to-be-friends: message me if you'd like to chat tonight, especially if you're leaving tomorrow! 🐍🗣️

I'll be somewhere near the convention center for at least a couple more hours tonight. 💖

If you'll be here during sprints, see you tomorrow! (I'm here until Wednesday)

@PyConUS

treyhunner, to python
@treyhunner@mastodon.social avatar

Python 3.7 reached the end of its life today. 🎉

Here are some Python 3.8 features you can now embrace:

• cached_property
• self-documenting f-string expressions
• walrus operator
• positional-only args
• passing dictionaries to reversed()

A few other favorites of mine:

• math.‍prod (like sum, but for multiplication)
• clearing the REPL with globals().clear()... this would break things in Python 3.7!
• argparse's add_argument method has an "extend" action

treyhunner, to python
@treyhunner@mastodon.social avatar

What feature or best practice do you wish everyone knew?

treyhunner, to python
@treyhunner@mastodon.social avatar

Listening to episode 1 of the new core.py podcast with @ambv & Pablo Galindo and Pablo mentioned that hitting the up arrow in the REPL might eventually show a block of code instead of just the last line!

I am SO excited for this! 💖🐍

I don't think Pablo promised that this would land in Python 3.13, but my brain heard "this will definitely land in Python 3.13".

I'll be tracking the change log while trying to avoid pestering the open source gift givers. 😁🎁

https://podcasts.apple.com/us/podcast/episode-1-core-sprint-in-brno-python-3-13-0-alpha-1/id1712665877?i=1000631860803

treyhunner, to random
@treyhunner@mastodon.social avatar

I am SO excited for the new Python REPL for 3.13 that I made the PR branch for this the default Python on my machine today so that I can test it out in the coming weeks.

If you use pyenv and you'd like to do the same, here the (AI-generated but seemingly correct) instructions I used: https://treyhunner.com/2024/05/installing-a-custom-python-build-with-pyenv/

Also listen to the core.py podcast with @ambv and Pablo Galindo Salgado. That's how I found out about this new feature months ago.

treyhunner, to random
@treyhunner@mastodon.social avatar

Come to the Westin lobby soon and I'll teach you a card game called Cabo

treyhunner, to random
@treyhunner@mastodon.social avatar

Anyone running Fedora willing to share what your /etc/inputrc file looks like? (assuming you haven't modified it)

treyhunner, to random
@treyhunner@mastodon.social avatar

Years ago, a meetup I helped organize explicitly added a CoC and we decided to note its importance during every meeting. I remember discussing with some members that having a CoC made them feel anxious that they might inadvertently violate the CoC. They were also concerned that some folks might even stop coming because we added a CoC.

My response at the time was "good".

Sometimes we take on discomfort to bring greater comfort to others.

Sometimes we exclude some in order to include others.

treyhunner, to random
@treyhunner@mastodon.social avatar

@hugovk I found 2 differences in some (very in-the-weeds) Python Morsels exercises on Python 3.13.

I think the first might be a bug and the second is probably the result of fixing a bug.

https://pym.dev/p/35r3x/

Any thoughts on whether either might matter for production code? Or insight into the CPython issues/PRs that fixed these? (I did a quick search but couldn't figure it out)

Happy to report either difference in behavior, but I don't want to clutter up the issue tracker with noise.

treyhunner, to python
@treyhunner@mastodon.social avatar

With Python's slicing syntax, the first item is the start index, and the second item is the stop index.

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

treyhunner, to random
@treyhunner@mastodon.social avatar

If you're at and want a bunch of Python Morsels stickers to bring back to your local meetup, message me. I brought many extras!

treyhunner, to instagramreality
@treyhunner@mastodon.social avatar

Not attending PyCon US and don't want to see all the social media posts about it? (I'll certainly be sharing some)

If you're on a Mastodon instance:

  1. look up the "filters" setting
  2. filter the phrase "PyCon" (no quotes)
  3. make sure not to check "whole word' (so and related phrases are filtered too)

https://docs.joinmastodon.org/user/moderating/#filters

treyhunner, to python
@treyhunner@mastodon.social avatar

I tell my students to make a new virtual environment for each project they work on.

This way, the third-party dependencies for each of your projects will isolated from each other. No need to untangle which project depends on what!

Also note that if you're using Anaconda, you'll want to use conda environments instead.

https://www.youtube.com/watch?v=JHl8ukLbClo

treyhunner, to python
@treyhunner@mastodon.social avatar

When I say "lightning talks" is there a particular conference lightning talk or lightning talk session that comes to mind for you?

Doesn't need to be your favorite talk/session, but just one that comes to mind.

Link me to it!

Thanks @ehmatthes for inspiring this question.

treyhunner, to python
@treyhunner@mastodon.social avatar

Python educators, mentors, and anyone else who has a though opinion on explaining :

Why do we use len(thing) in Python instead of thing.len(), thing.length(), or thing.length?

I know my usual answer, but I wan to hear yours. How do you explain the reason behind this?

treyhunner, to random
@treyhunner@mastodon.social avatar

Today is the day we celebrate the pale blue dot in the middle left of this photo. 🌏

This is the only habitable home we'll have for hundreds of years, if not forever. Let's continue trying to make this place happy and habitable.

Happy 🌱

treyhunner, to python
@treyhunner@mastodon.social avatar

Scenario: a self-taught programmer with a few years of experience is trying to land their first tech job as a web dev. 🎓💰

They're really struggling with data structures & algorithms. 🔗

They're following some courses online and attempting Leetcode exercises on DSA-related topics and finding the whole topic very difficult.

What advice would give? 🤔

(Asking for an Internet acquaintance)

treyhunner, to python
@treyhunner@mastodon.social avatar

One of these functions prints and the other returns, but they seem like they do the same thing.

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

#python

treyhunner, to random
@treyhunner@mastodon.social avatar

The longer my articles get, the more useful I find emoji in breaking up the sections with a tiny image.

While drafting the "Every dunder method in Python" post, I asked both Chat GPT and Claude AI for emoji for each section header. That was surprisingly helpful! I discovered that Claude was a bit better than Chat GPT for this task.

If only I had these LLMs back when I hand-picked all the emoji for my "How to have a great first PyCon" post. 😆

treyhunner, to python
@treyhunner@mastodon.social avatar

Python includes 103 "normal" dunder methods, 12 library-specific dunder methods, and at least 52 other dunder attributes of various types.

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

  • All
  • Subscribed
  • Moderated
  • Favorites
  • megavids
  • thenastyranch
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • ngwrru68w68
  • provamag3
  • magazineikmin
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • JUstTest
  • All magazines