@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, to random
@treyhunner@mastodon.social avatar

Out of curiosity, I searched for the hashtag on Mastodon and Twitter and scrolled back 16 hours and started counting posts. 🤔

I counted:

87 posts on Twitter on the PyCon hashtag 🐦

134 posts on Mastodon on the PyCon hashtag 🐘

The PyCon conversations have finally moved (mostly) to Mastodon! 🙌

Not a HUGE difference, but enough that I felt like there was more activity and decided to confirm my suspicion. 💗

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

My students often ask me whether they can see a list of every dunder method that has. I've been meaning to compile a categorized list for years.

I finally did it.

Here's every dunder method in Python... all 115 of them! 🤯

https://pym.dev/every-dunder-method/

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

I've just updated my ~/.config/pip/pip.conf & my dotfiles repo to disallow pip installing outside virtual environments! 🎉

TIL 2 things about 's pip:

  1. pip has a config file. If I ever knew this, I'd forgotten.

  2. pip has an option that stops it from working outside of a virtual environment!

This is great for me because I use pipx and NEVER do global pip installs.

Info: https://unix.stackexchange.com/questions/492041/is-there-a-way-to-disable-pip-outside-of-a-virtual-environment

Thanks to @hynek's excellent uv video for this semi-related TIL 💜 https://youtu.be/_FdjW47Au30?si=5iRmMuWMdewRubNt

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

Python 3.13 beta 1 just landed.

My favorite new feature is the new REPL.

Honestly, this may be my favorite feature since f-strings.

My write up on the differences between old and new REPLs:
https://treyhunner.com/2024/05/my-favorite-python-3-dot-13-feature/

treyhunner, to python
@treyhunner@mastodon.social avatar

Python Community News released videos for 13 of the 15 nominees running for @ThePSF board of directors right now.

If you haven't voted yet, check these videos to hear each nominee answer a few questions.

https://www.youtube.com/playlist?list=PL9MuO5r3rpXJ5k-NEI3Gc6S3CZU7mGwvP

Thanks @kjaymiller & @jonafato for putting these together.

treyhunner, to python
@treyhunner@mastodon.social avatar

The ruff linter can now replace all my favorite linting & auto-formatting tools.

For many months, I've used these commands:

• ruff check . # lint
• ruff check --fix . # auto-fix

Now I also use:

• ruff format . # A Black equivalent

Instead of flake8 or pylint, I either use the ruff defaults (similar to flake8) or I enable the "PL" rules for pylint.

The --fix argument will auto-fix many linting errors too (similar to autopep8, autoflake, isort, pyupgrade, etc.).

treyhunner, to python
@treyhunner@mastodon.social avatar

I attended my first Python conference 10 years and 10 days ago.

I wrote a meandering and nostalgic blog post (complete with links to old group selfie tweets) about the last 10 years of being part of the wider community.

I'm really grateful I decided to attend PyCon 2014 and that I came back for PyCon 2015 and went to DjangoCon 2015 as well.

https://treyhunner.com/2024/04/10-years-of-python-conferences/

treyhunner, to random
@treyhunner@mastodon.social avatar

I've told my students that even though comprehensions are faster than loops, much of a loop's slowness was due to append method lookup time.

I just discovered that my knowledge is outdated.

Since Python 3.11, this "append" optimization isn't any faster! https://pym.dev/p/2gzr3/

This is thanks to PEP 569, which made method call lookups and lots of other stuff a bit faster.

https://docs.python.org/3/whatsnew/3.11.html#pep-659-specializing-adaptive-interpreter

More context (someone else noticed this a few days before I did): https://discuss.python.org/t/append-mylist-append-optimization-now-harmful/36028

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

I'm doing something I've never done: I'm offering lifetime access to Morsels. ♾️

You can get access to all screencasts, articles, and exercises I publish for the price of a 2 year subscription. 🐍

This sale ends on November 27, 2023 💸

https://pym.dev/lifetime-access-sale

treyhunner, to python
@treyhunner@mastodon.social avatar

I'm offering lifetime access to Python Morsels from now through Monday. 🐍

If you're a frequent user and you plan to use it for at least a few more years, I highly recommend this deal. 💖

More details at https://pym.dev/lifetime-access-sale

video/mp4

treyhunner, to django
@treyhunner@mastodon.social avatar

A controversial topic:

class-based views (CBVs) or function-based views (FBVs)? 🤔

I started with function-based views, but after a few years of using Django I pretty much moved fully to class-based views. Both have pros & cons (and vocal advocates).

The Django docs introduce FBVs first and then discusses CBVs as well as Django's built-in "generic class-based views" (GCBVs).

Django-REST-Framework also makes heavy use of CBVs.

But class-based views CAN be confusing.

treyhunner, to random
@treyhunner@mastodon.social avatar

What tips do you have for folks thinking of trying out Mastodon during this year?

3 of my tips:

  1. Follow the hashtag (yes you can follow a hashtag just like following a profile!)
  2. If you post and realize you forgot the hashtag, don't delete your post. Just edit it!
  3. Consider following the hashtag also. Many folks use it without realizing that is the official one.

What tips do you have?

treyhunner, to programming
@treyhunner@mastodon.social avatar

I always love chatting with Jay Miller. 💖

@kjaymiller interviewed me at during the first day of sprints.

We chatted about:

• interacting with folks without discussing
• playing (my version of)
• how great chatting with other teachers & learners is
• getting feedback and validation
• contributing during sprints

Jay also interviewed @AlSweigart @pythonbynight, @ericholscher, @sethmlarson, Aseda Addai-Deseh, and @freakboy3742. Check the playlist!

https://www.youtube.com/watch?v=HzuXmzhFJ6Y&list=PL9MuO5r3rpXK_dfGDIlKqjiKZ5_YqZgxj&index=3

treyhunner, to python
@treyhunner@mastodon.social avatar

What are some of your favorite analogies that work well in ?

Or... what's an analogy that doesn't work so well in Python?

Some examples that I often reach for:
• Lists as a stack of plates
• Duck typing versus checking the DNA of an animal
• Private variables in Python as a closed but unlocked door
• Iterators as PEZ dispensers
• super().my_method(*a, **k) as a form of "passing the buck"

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

I'm drafting a tip email about time complexity and I can't help but reference Ned Batchelder's Big-O talk/article. 💖

In particular, I love the stickiness of this succinct rhyme:

> How code slows as data grows

That phrase is just such an excellent summary of time complexity & Big O. Thanks @nedbat! 👏

https://nedbatchelder.com/text/bigo.html

treyhunner, to python
@treyhunner@mastodon.social avatar

When I say "lightning talks" is there a particular #Python 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, (edited ) to python
@treyhunner@mastodon.social avatar

You're about to start a new pip-installable project.

What do you do?

treyhunner, to python
@treyhunner@mastodon.social avatar

If you're a user and a lifelong learner, I have a sale for you. 🐍

From now through next Monday, I'm offering lifetime access to Python Morsels for the price of a 2-year subscription. 💸

Every week, I'll recommend an exercise that will push you just outside your comfort zone. 🧪

Feel free to message/email me if you have any questions. 💖

https://pym.dev/lifetime-access-sale/

treyhunner, to python
@treyhunner@mastodon.social avatar

Need to read a CSV file in Python?

You can use the csv module from the standard library!

The reader class will convert the CSV rows into lists.

The DictReader class will convert the CSV rows into dictionaries (treating the first row as headers).

https://youtu.be/9AJvH-nM5zs?si=RBCxIwjlkCKlmepV

treyhunner, to random
@treyhunner@mastodon.social avatar

Don't overlook the the "outdoor space" doors in the conference center at
@pycon this year!

The first space looks inviting and it is! ✅

The second space looks like it's just concrete stairs 🤔

... but there's a great view up those stairs, including plants & benches! 😮🌿🪻🐝

You can also take the elevator to 4 or 4R to get there.🛗

Rooftop with plants and benches
View of the river and bridges

treyhunner, to random
@treyhunner@mastodon.social avatar

Coming to @pycon next week?

If this is your first , join us for the Newcomer's Orientation before the opening reception on Thursday!

https://us.pycon.org/2024/events/newcomer-orientation/

Also see my post on how to have a great first PyCon as well @brainwane's post for folks who've already attended a conference before.

https://treyhunner.com/2018/04/how-to-make-the-most-of-your-first-pycon/
https://www.harihareswara.net/posts/2023/your-first-pycon-but-not-your-first-convention/

treyhunner, to django
@treyhunner@mastodon.social avatar

The most important Django resources I can recommend: djangopackages.org and awesomedjango.org

Read the full article: Django June 2023
https://trey.io/duqrY0

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

I just watched @pythonbynight's talk on the current state of in and now I'm turn between trying out django-render-block, forge-htmx, and @carlton's django-template-partials.

https://github.com/clokep/django-render-block
https://github.com/forgepackages/forge-htmx
https://github.com/carltongibson/django-template-partials/

Anyone written a blog post or made a repository attempting to write the same HTMX-powered view(s) using all 3 of those packages? I'd love to compare and contrast them more directly.

Here's the talk:

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

treyhunner,
@treyhunner@mastodon.social avatar

I just watched @_chrismay's talk, which also discusses HTMX but is (mostly) much higher-level and focused heavily on improving user experience.

Great visual story-telling Chris! 👏

https://youtu.be/kYV8K71pY64

treyhunner, to random
@treyhunner@mastodon.social avatar

What are some of your favorite @pycon tips? 💡

Reply and tag . 💖

treyhunner,
@treyhunner@mastodon.social avatar

More tips from @brainwane:

• volunteering is a great way to meet new people (& be part of the event)
• submit a lightning talk (sign up ASAP)
• chat with vendors in the expo hall
• try to follow the PacMan rule in conversations (leave a space open for someone new to join in)

https://www.harihareswara.net/posts/2023/your-first-pycon-but-not-your-first-convention/

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