@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

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

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

b0rk, (edited ) to random
@b0rk@jvns.ca avatar

me, 3 years ago: “I have no idea if this selling printed copies of zines thing will work out, better just order 300 copies to be safe’"

me, today: oh looks like we've sold 1800 total print copies of “How Containers Work” and we're almost out of stock AGAIN, time to make another order

I guess I'll just order 2000 print copies of How Git Works in the first place this time :)

treyhunner,
@treyhunner@mastodon.social avatar

@b0rk just told my mailing list about it this morning because it's so much better than the other resources I've been recommending about git! 👏

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

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

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

#Python

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/

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. 😁

18+ lacey, to random
@lacey@hachyderm.io avatar

I’m talking about me! 👋

I’m writing TILs and ready for a next step. I tried a micro blog but it didn’t “fit.” I do have a website with a blog, but I’m looking for something between a TIL and an actual post on my blog. Thoughts?

treyhunner,
@treyhunner@mastodon.social avatar

@ryancheley @lacey @CodenameTim I may be interested in this.I already have one writing session each week but I could use another.

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

treyhunner,
@treyhunner@mastodon.social avatar

@cm_jc triple quotes aren't necessarily "bad" but I recommend against them to reduce the surprise factor when reading code.

Likewise I'd recommend this:

try:
something()
except:
pass. # suppress all exceptions

Over this:

try:
something()
except:
"suppress all exceptions"

The second one includes a string all on its own which Python won't parse. But as a Python programmer looking at that code, I don't immediately think "this string is a comment".

treyhunner,
@treyhunner@mastodon.social avatar

@cm_jc I would definitely use a multi-line string. But that string wouldn't be ignored by Python. It would be interpreted as a string.

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'm creating an article that details every module that can be run as a script with "python -m", including the weird and lesser used ones.

treyhunner,
@treyhunner@mastodon.social avatar

@bmispelon I'm not sure I'd call this method "better", but it's different.

Since I'm actually importing each of these modules, I had to deliberately skip certain modules that hang the interpreter when run when name is set to "main". 😬

https://pym.dev/p/2eyt4/

treyhunner,
@treyhunner@mastodon.social avatar

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

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

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. 😅

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

treyhunner, to python
@treyhunner@mastodon.social avatar

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

• "==" 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!

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