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

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!

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 #PyConUS 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

#Python

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!

tonybaloney, to random
@tonybaloney@fosstodon.org avatar

Spot what's new ๐Ÿง

treyhunner,
@treyhunner@mastodon.social avatar

@tonybaloney the fact that your exit doesn't need parenthesis after it ๐Ÿ’ก

treyhunner, to python
@treyhunner@mastodon.social avatar

Which means we can use "next" to get the first item from any iterable as long as we pass that iterable to the built-in "iter" function first

Read more ๐Ÿ‘‰ https://trey.io/UFI8MG

treyhunner, to random
@treyhunner@mastodon.social avatar

The Python Morsels REPL (https://pym.dev/repl) now properly supports using Ctrl+D to stop standard input! A user recently tested out code that relied on sys.stdin.read() and ended up stuck without a way to send EOF.

Thanks @notsolonecoder for a 1.5 year old unmerged CPython PR that contained the keys to fixing this issue!

https://github.com/python/cpython/pull/97665

treyhunner,
@treyhunner@mastodon.social avatar

@pg @notsolonecoder yes it's fully in-browser, running on CPython compiled to WebAssembly via Emscripten.

The Python Morsels exercise automated tester is powered by this as well, so user solutions run right in the browser.

Also this pastebin tool runs on the same system: https://pym.dev/p

I'm not using pyodide because I don't want to allow arbitrary JS code execution. A pyodide dev told me that I could have put a wrapper/sandbox around pyodide to accomplish something similar as well.

treyhunner,
@treyhunner@mastodon.social avatar

@pg Yup! @notsolonecoder has given a number of talks on WebAssembly and CPython: https://www.youtube.com/results?search_query=katie+bell+webassembly

I understand the concern of load time. Since the running on Python Morsels is triggered by the user, the wasm file is often loaded by the time the user hits the run button and when it's not it typically only adds a couple seconds delay.

I'm hoping smart folks find a way to make the initial wasm file that's sent considerably smaller.

treyhunner,
@treyhunner@mastodon.social avatar

@notsolonecoder I think it would be!

I've also thought of trying to at least make a better demo for folks that lives outside of CPython's repo. I'd be happy to collaborate on and/or beta test either/both of these things.

Completely separately: support for WebAssembly support for readline and curses one day would be incredible. Both are required for the brand new Python REPL in CPython's main branch, which I'm pretty sure means no new-style REPL in WASM land. This seems far less trivial though.

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
  • โ€ข
  • megavids
  • kavyap
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • InstantRegret
  • GTA5RPClips
  • Youngstown
  • everett
  • slotface
  • rosin
  • osvaldo12
  • mdbf
  • ngwrru68w68
  • JUstTest
  • cubers
  • modclub
  • normalnudes
  • tester
  • khanakhh
  • Durango
  • ethstaker
  • tacticalgear
  • Leos
  • provamag3
  • anitta
  • cisconetworking
  • lostlight
  • All magazines