Posts

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

treyhunner, to python
@treyhunner@mastodon.social avatar

I made a decorator that immediately calls the function it decorates within a loop.

I do not regret my decision.

https://treyhunner.com/2024/06/a-beautiful-python-monstrosity/

glyph,
@glyph@mastodon.social avatar

@treyhunner I do this all the time. Literally today, even :-)

treyhunner,
@treyhunner@mastodon.social avatar

@glyph Did you write a post on this at some point?

I could have sworn I'd seen someone else demonstrating a similar legitimate-but-weird use of a decorator that performed actions at decoration time.

treyhunner, to python
@treyhunner@mastodon.social avatar

Well, if you're trying to delete a block of code but you don't want to lose it, and you're using Git (or a similar version control system) I would commit that code to Git and then delete it.

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

#Python

treyhunner, to python
@treyhunner@mastodon.social avatar

Recursion happens when a function calls itself.

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

treyhunner, to python
@treyhunner@mastodon.social avatar

The exclusivity of the stop index actually has a nice side effect: if you slice up to index 3 and then start slicing again from 3 onward, those two slices won't overlap.

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

#Python

treyhunner, to python
@treyhunner@mastodon.social avatar

If you find the "next" function confusing, you can always use a for loop and a break statement instead

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

#Python

treyhunner, to random
@treyhunner@mastodon.social avatar

Best out of context TODO I've written in a while. 🪑

treyhunner,
@treyhunner@mastodon.social avatar

@erwinrossen I absolutely do. It's a reference to a YouTube video about ontology.

https://youtu.be/fXW-QjBsruE?feature=shared

pradyunsg,
@pradyunsg@mastodon.social avatar

@treyhunner It's a good video!

treyhunner, to python
@treyhunner@mastodon.social avatar

If you're trying to write documentation, you probably want a docstring instead of a comment.

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

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

New article on Python's many command-line tools 📣

Did you know that 3.12 comes bundled with 50 command-line tools? 😮

An HTTP server, a sqlite prompt, a code profiler, and so much more! ✨

https://pym.dev/cli-tools/

hugovk,
@hugovk@mastodon.social avatar

@treyhunner Coming soon in 3.13: a random CLI! 🎲

$ python -m random curry "fish n chips" tacos
curry

$ python -m random 6
6

https://docs.python.org/3.13/library/random.html#random-cli

treyhunner,
@treyhunner@mastodon.social avatar

@hugovk Ooh! I missed this new feature!

This one actually seems really handy 💖

$ python3.13 -m random 6
1
$ python3.13 -m random 3.14159
3.0145311549545397
$ python3.13 -m random this is great
is

I will definitely be updating this article before October. 😁

treyhunner, to python
@treyhunner@mastodon.social avatar

For single-line comments, Python uses the octothorpe character (#), also known as pound, number sign, crunch, and of course, the hashtag character

Read the full article: Multiline comments in Python
https://trey.io/a5O8qe

#Python

cm_jc,
@cm_jc@sigmoid.social avatar

@treyhunner like this?

treyhunner,
@treyhunner@mastodon.social avatar

@cm_jc yup just like that. Multi-line strings are great as strings.

They're also great as docstrings: https://pym.dev/docstrings/?watch

But I wouldn't use them as an equivalent to "multi-line comments" in another language (unless everyone else on your team reading your code is already bought in on that odd use).

treyhunner, to random
@treyhunner@mastodon.social avatar

@bmispelon I just ran across a slidedeck of yours from 2013!

I searched Kagi for "python -m pyclbr" and there were only about 6 results. Yours was one of them.

https://speakerdeck.com/bmispelon/stdlib-safari-exotic-animal-edition?slide=91

treyhunner,
@treyhunner@mastodon.social avatar

@bmispelon I've decided that pyclbr is pronounced "pickle bear" 🥒🐻

bmispelon,
@bmispelon@mastodon.social avatar

@treyhunner a+ emoji game right there 💯

treyhunner, to python
@treyhunner@mastodon.social avatar

Pro tip: While time-boxing and removing distractions are great for solving programming exercises, they're also great for entering a flow state for the purpose of studying at school or getting difficult tasks done at work.

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

#CodingChallenge #Python

treyhunner, to python
@treyhunner@mastodon.social avatar

Today I'm wondering how I could get the new Python 3.13 REPL working in WebAssembly in the browser. 🤔

xterm-pty for xterm.js looks possibly helpful, but I'm unsure how to use it: https://github.com/mame/xterm-pty

I'm also wondering what CPython will need to be configured in its environment to properly trigger the new REPL.

I'm a TTY novice and definitely feel in over my head with this train of thought. 😅

#Python #WebAssembly #CPython #WASM #Emscripten #xtermjs

treyhunner,
@treyhunner@mastodon.social avatar

I'd love to collaborate with (or shamelessly copy/mimic!) smart folks like the Pyodide devs, the PyScript devs, or @notsolonecoder... but this new REPL is so new that I doubt many WebAssembly-oriented folks have tried playing with this yet!

This thought path did inspired me to rewatch @phildini and Asheesh's talk on Python & TTYs.

It's even more interesting than I remember, possibly because I care more about TTYs now than when I fist watched it!

https://youtu.be/XVhSjZYwZJo?si=fCQ89vmrrZL4cQyY

treyhunner, to python
@treyhunner@mastodon.social avatar

The next time you find an if-else in your code where both the "if" and the "else" return from the function that you're in, you could think of that "else" as unnecessary.

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

treyhunner, to python
@treyhunner@mastodon.social avatar

The start index is inclusive, but the stop index is exclusive, meaning Python stops just before the stop index.

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

#Python

treyhunner, to python
@treyhunner@mastodon.social avatar

What's the difference between "==" and "is" in #Python?

• "==" checks for equality (do 2 objects represent the same value)
• "is" checks for identity (do 2 variables/references point to the same object)

https://pym.dev/equality-vs-identity/

treyhunner,
@treyhunner@mastodon.social avatar

@briz I'm glad you learned something new!

j7an,
@j7an@mastodon.social avatar

@treyhunner actually experienced this very issue during Pallets Sprints last week while troubleshooting one of the GitHub issues for Jinja.

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