@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, (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. 😁

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

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

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 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" 🥒🐻

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

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