@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 python
@treyhunner@mastodon.social avatar

Reversing a list is the most common use for the step value when slicing, though I typically prefer to use Python's built-in reversed function instead

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

treyhunner, to python
@treyhunner@mastodon.social avatar

Every function in Python returns something, even functions without any return statement.

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

treyhunner, to random
@treyhunner@mastodon.social avatar

Planning my veg-ish eating for

Rosewater Middle Eastern looks like it has good veg options and Arepittas looks like it probably does too.

ShadoBeni also looks really good, though it's a bit of a walk from the conference center.

Folks eating vegan/vegetarian this trip: found any other eats that look promising?

(Editing to also add the not-officially-recognized but widely used hashtag as well 🤫)

treyhunner, to random
@treyhunner@mastodon.social avatar

Pretty sure I just saw a former Python BDFL while getting in my Lyft. I think that means I'm in the correct airport.

webology, to random
@webology@mastodon.social avatar

📝 On Hashtag Accessibility

I’m calling myself out for this because until about a month ago, I used hashtags all the wrong way on my social media posts.

You can make your posts easier with screen readers with a tiny change:

> Capitalize the first letter of each word in your hashtag

https://micro.webology.dev/2024/05/14/on-hashtag-accessibility.html

treyhunner,
@treyhunner@mastodon.social avatar

@webology I pretty much always do this when there's multiple words because I also find a multiwordalllowercasehashtag hard to read. I'm not sure whether I do this consistently for single word hashtags though. 🤔 I'll keep this in mind.

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 #PyConUS and related phrases are filtered too)

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

treyhunner, to python
@treyhunner@mastodon.social avatar

Most importantly, asking whether a set contains an item (item in my_set) is fast, unlike lists. https://trey.io/d8D57O

pythonbynight, to random
@pythonbynight@fosstodon.org avatar

This is a little hard to write, but sadly, I'll be missing PyCon US this year. Long story short: I hurt my knee. Still on crutches. Surgery likely...

I came close to hopping (literally) on a plane and heading out anyway, but it's probably not the wisest choice.

For those of you heading out, enjoy the conference, meet someone new, volunteer, and have fun!

Maybe I'll catch you at the next one!

#PyConUS

treyhunner,
@treyhunner@mastodon.social avatar

@pythonbynight I'm so sorry Mario! I hope you recover soon. 💗

treyhunner, to random
@treyhunner@mastodon.social avatar

Who else will be at this week? 🐍✨

scerruti, to random
@scerruti@csed.social avatar

@treyhunner are you aware of any way to deal with IEEE 745 Single Precision floats in Python on a bit level? I'm trying to do something stupid as a demo for class and it works but it's slow.

https://github.com/e3-cerruti/jupyter-calculus/blob/main/Applicatons%20of%20Newton's%20Method.ipynb

treyhunner,
@treyhunner@mastodon.social avatar

@scerruti working with bytes instead of strings should be faster. Anything implement in Python itself will be slower, but working with the actual bytes instead of strings should remove some overhead.

struct may or may not be useful (I haven't implemented this myself, at least not in many years).

I'd ask Claude, MS Copilot/GPT 4, and Gemini for a better solution that's lower level and see what they come up with. Could be a start or might not work, but might have some time.

treyhunner, to python
@treyhunner@mastodon.social avatar

Python's "next" function is designed to be used with iterators.

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

hynek, to python
@hynek@mastodon.social avatar

In my quest to produce a shorter video, I’ve produced my longest so far:

tox vs Nox: What are they for & How do you choose?: https://www.youtube.com/watch?v=ImBvrDvK-1U

In which I introduce those two indispensable tools and reflect my own usage of BOTH. Enjoy!

treyhunner,
@treyhunner@mastodon.social avatar

@hynek another video that taught me something that wasn't the primary purpose of the video!

I'm now using Python version classifiers to control GitHub actions & nox versions. ✅

https://github.com/treyhunner/countdown-cli/pull/208/commits/d33716b471a028ee1c56e35672e94e896dc5f360

Thanks! 💗

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 python
@treyhunner@mastodon.social avatar

The bisect module has an implementation of binary search for you.

Read the full article: Python Big O: the time complexities of different data structures in Python
https://trey.io/d8D57O

treyhunner, to random
@treyhunner@mastodon.social avatar

@pycon just a thought, but you may want to put in your bio so folks know that's the official hashtag.

I often see folks assuming it's when it should be .

treyhunner, to python
@treyhunner@mastodon.social avatar

What are your favorite one liners?

treyhunner,
@treyhunner@mastodon.social avatar

@rochacbruno nice one.

In case you're unaware of it:

export PYTHONBREAKPOINT="ipdb.set_trace"

https://kortina.nyc/notes/use-ipdb-as-the-default-python-debugger-with-breakpoint-and-pythonbreakpoint/

treyhunner,
@treyhunner@mastodon.social avatar

@iris Great ones!

Here's an even shorter equivalent to locals():

vars()

Relatedly: dir() (for just the names)

Also vars(an_object) or dir(an_object).

Since vars(an_object) only looks at dict they're a bit different. Sometimes I'll do vars(an_object).keys() to see just the attributes that live directly on an object.

bmispelon, to django
@bmispelon@mastodon.social avatar

New article on my blog: a ORM technique I found for combining JSONObject and Subquery to build model instances: https://blog.bmispelon.rocks/articles/2024/2024-05-09-django-getting-a-full-model-instance-from-a-subquery.html

treyhunner,
@treyhunner@mastodon.social avatar

@bmispelon This is so clever! 🎉And a great write up! 👏

I appreciate your "attempt 1", "attempt 2", style write ups in general. It makes me feel like I'm suffering through searching for the solution along with you. 😆

treyhunner, to python
@treyhunner@mastodon.social avatar

You may be wondering, why is the start index included, but the stop index is excluded?

Read the full article: List slicing in Python
https://trey.io/ZEuawA

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

@minkiu The Venn diagram overlap would be a circle within a circle.

Then new REPL isn't meant to replace bpython, ptpython, or IPython. But it does borrow some of my favorite features.

treyhunner,
@treyhunner@mastodon.social avatar

@bobmagicii when you type "exit" it... Exits! 🎉

treyhunner,
@treyhunner@mastodon.social avatar

@chrysn @fohrloop I imagine someone motivated to make that change would need to do it.

I assume "-m asyncio" makes up a fairly small portion of all REPL usage. That doesn't mean it is unimportant to those who use it of course!

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

@_KevinTrainor 👍 I'll give this some more thought after PyCon. Thanks!

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