@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

Variables in Python are NOT like buckets that contain objects ❌πŸͺ£

Variables are "pointers". Imagine an arrow pointing from a variable to an object.

my_name ⇨ "Trey Hunner"

https://pym.dev/variables-are-pointers/?watch

CodenameTim, to django
@CodenameTim@fosstodon.org avatar

Coming back at update_or_create for round 2!

If you call update_or_create where the instance already exists and the defaults passed in are already the values on the instance, do you ever want it to actually re-save the instance?

I'm running into the case where I'd prefer it to not update the instance if it doesn't need to. I'm guessing I'm overlooking some race condition problem though.

treyhunner,
@treyhunner@mastodon.social avatar

@webology @ryanhiebert @CodenameTim I thought some folks added functionality to simple history to control whether/when a history snapshot happens.

treyhunner,
@treyhunner@mastodon.social avatar

@CodenameTim @webology @ryanhiebert
It was skip_history_when_saving that I was thinking of. I had thought of using that with django-lifecycle in the past. My data duplication issue didn't end up being too big of a problem though, so I never got around to it.

The biggest upside of django-simple-history is also it's biggest upside: it's automatic. 😬

treyhunner,
@treyhunner@mastodon.social avatar

@ryanhiebert @CodenameTim @webology I actually made FieldTracker because I was inspired by django-simple-history and thought django-model-utils might be a good home for that. 😜

Honestly I use django-lifecycle's dirty-checking more often now since it's good enough for my use cases.

treyhunner, to python
@treyhunner@mastodon.social avatar

With the "else", this code looks to me a bit like a balance scale, with an "if" and an "else" on either side.

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

treyhunner, to random
@treyhunner@mastodon.social avatar

@buttondown will you have a booth at @pycon? I'm curious to know how Buttondown compares to my current email/newsletter setup and would love to chat with folks in-the-know.

Regardless of whether you'll have a booth, thank you for sponsoring! πŸ’–

chrisyxlee, to python
@chrisyxlee@hachyderm.io avatar

TIL in my adventures, the proper way to set up a class that returns itself is to use the Self typing annotation and return values by calling self.__class__ on the new value

from typing import Self  
class ImActuallyAString(str):  
 def one_longer(self) -> Self:  
 return self.__class__(self + "one")  

α••( ᐛ )α•— (please tell me if I'm wrong lol)

treyhunner,
@treyhunner@mastodon.social avatar

@chrisyxlee I always forget about typing.Self πŸ‘

I'd call type(self)(...) on the new item. I prefer to avoid dunder attributes when there's a higher-level way to access the same thing.

This is not a universally agreed upon convention though, as there are parts of CPython's source code that use self.class and parts that use type(self). Most of the self.class parts are older and may have predated type(...) being usable (old-style classes didn't work well with type back in Python 2).

carlton, to random
@carlton@fosstodon.org avatar

We’re on 314 now. You’re all lovely πŸ₯°

From: @carlton
https://fosstodon.org/@carlton/112359422380857316

treyhunner,
@treyhunner@mastodon.social avatar

@pythonbynight @carlton 316 πŸ’—

treyhunner, to random
@treyhunner@mastodon.social avatar

I subscribed to an open source PR months ago for a feature I really want to see happen. It sat dormant for months and activity started up again this weekend. I've been excitedly watching commit pushes over the last few days. I'll be silently cheering on the sidelines and looking forward to enthusiastically alpha/beta-testing this feature once it's ready.

πŸ’– @ambv: cheering you and Pablo on πŸ‘

treyhunner, to random
@treyhunner@mastodon.social avatar

I've had Moonage Daydream playing in my head since I woke up. Looks like that'll be my brain's background track while teaching today. 🎢

treyhunner,
@treyhunner@mastodon.social avatar

During each of the breaks during today's sessions I'm finding that Mr. Mastodon Farm is stuck in my head. 🎢 One weird song to another. 🀷

treyhunner, to python
@treyhunner@mastodon.social avatar

The index method is for making integer-like objects.

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

treyhunner, to python
@treyhunner@mastodon.social avatar

So before you remove that "else" statement, think about whether it makes your code more readable or not.

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

treyhunner,
@treyhunner@mastodon.social avatar

@bugroar It's an option! Though in this case the "blah" would be pretty long.

treyhunner, to python
@treyhunner@mastodon.social avatar

This week's Python tip email will be my 100th one! πŸŽ‰

I just realized this while planning the email this morning. I'm glad I thought to check when 100 would be! πŸ’―

That's 2 base-10-based anniversaries within a couple weeks (over the weekend I also shared that I just passed my 10 year anniversary of attending Python conferences). πŸ”Ÿ

This week's tip will be related to an activity that got me into this whole Python community thing. πŸ’–

If you're into newsletters & : https://pym.dev/newsletter πŸ’Œ

ehmatthes, to random
@ehmatthes@fosstodon.org avatar

Python people, do you make short-lived intermediate variables to make your return statements readable?

For example, which of these would you tend to prefer?

def get_project_name(output_str): """Get project name from output of

treyhunner,
@treyhunner@mastodon.social avatar

@ehmatthes this is pretty much the example I give for when I remove that extra variable.

When the function is named "get_something" and the last line is "return something", I'd rather remove the "something" variable when possible.

If the function name isn't the same as the variable name or the variable is assigned somewhere that isn't immediately before the last "return", I'd leave it.

Otherwise, I always remove it.

treyhunner,
@treyhunner@mastodon.social avatar

@ehmatthes since I readability isn't an issue in this case (IMO) because the function name is the same as the variable name, the main reason I usually hear argued for keeping it is for the sake of ease of debugging.

I might add the variable back temporarily when debugging (just as I might unwrap a comprehension into a loop). Though PDB has a "retval" command for this purpose.
https://docs.python.org/3/library/pdb.html#pdbcommand-retval

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

What are your feelings on capital punishment?

This is obviously completely unrelated to Python, but I'm just curious how my follower's beliefs on this compare to the overall beliefs in my region of the world.

ehmatthes, to random
@ehmatthes@fosstodon.org avatar

I'm embarrassed to admit that I almost exclusively listen to ambient music now while working.

I used to be able to listen to just about anything instrumental, but now I find anything more than ambient distracting.

treyhunner,
@treyhunner@mastodon.social avatar

@ehmatthes I pretty much exclusively listen to Brian Eno's Music For Airports. That is my working album, so much so that hearing it in other context reminds me of attempting to enter a flow state.

bbelderbos, to github
@bbelderbos@fosstodon.org avatar

A cool way to keep your profile up2date is by creating a self-updating Readme, a trick I picked up from Simon Willison.

Here is how I made mine pulling in different feeds:
https://pybit.es/articles/how-to-create-a-self-updating-github-readme/

I hope it inspires you to make your profile more engaging.

treyhunner,
@treyhunner@mastodon.social avatar

@bbelderbos Neat trick! I may end up doing some variation of this. Thanks for sharing Bob. πŸ’—

webology, to random
@webology@mastodon.social avatar

πŸ€” Some day I will recount the story of how I met @treyhunner after I just chaired my first @djangocon in Austin, TX.

Today is not that day. 🀣 https://mastodon.social/@treyhunner/112344745965219473

treyhunner,
@treyhunner@mastodon.social avatar

@webology I'm glad I ran into you than night! 😊

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/

webology, to random
@webology@mastodon.social avatar

πŸ”₯ Drop Google Chrome and try out Vivaldi for a week, I dare you.

#Enshittification
https://micro.webology.dev/2024/04/27/drop-google-chrome.html

treyhunner,
@treyhunner@mastodon.social avatar

@mahryekuh

The biggest upsides so far:

  1. All the options
  2. The unconventional but nice defaults for many of the options

The biggest downsides:

  1. All the options
  2. The unconventional and weird defaults for many of the options

I've spent so much time configuring it over the last week. 😬 Enjoying it so far though.

@webology, I'd love to see a write-up on the options you've tweaked from the defaults. I'd share something similar, but I haven't figured out how to determine what I changed.

treyhunner, to python
@treyhunner@mastodon.social avatar

I'm 30 away from 3,000 subscribers on the Python Morsels YouTube channel. πŸπŸ“Ί

If you're a YouTube user and you like , subscribe! πŸ””

I share one very short Python screencast or a YouTube short every week.

https://www.youtube.com/PythonMorsels

treyhunner, to random
@treyhunner@mastodon.social avatar

Tip for Trello users who miss the old markdown editor:

Open up your browser's inspector, navigate to "Local Storage" and add:

β€’ Key: featureFlagOverrides
β€’ Value: {"aaaa.web.editor": false}

Every Trello card will now use the old markdown-style editor. βœ…

Note that the above is all case sensitive, since that's a variable name and a JSON blob.

I really hope never removes this hidden feature flag because I rely heavily on markdown in my Trello cards. πŸ˜…

  • 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