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

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

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

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

sonicrocketman,
@sonicrocketman@mastodon.social avatar

@treyhunner Congrats on making HN! Very useful stuff. I use http.server and sqlite a lot. Some are new to me though.

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

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

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.

treyhunner, to random
@treyhunner@mastodon.social avatar

I posted a rambling reflection on my experience.

See you in Pittsburgh again in 2025!

https://treyhunner.com/2024/05/pycon-2024-reflection/

treyhunner,
@treyhunner@mastodon.social avatar

This post contains over 2 dozen links to Mastodon, GitHub, Twitter, or LinkedIn profiles.

I tried to drop a relevant link for every name that I mentioned. And there were so many names that I didn't mention... of folks I dined with, chatted with, watched speak, or interacted with in some other way.

💖 I'm looking forward to seeing you all again soon!

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

After many months of using Discord, I finally realized (thanks to seeing @nedbat's computer at PyCon) that it has a light theme. 💡

In hindsight it seems obvious that it doesn't need to be dark, but this never occurred to me before. 😅

I suddenly sort of like this app. It's interesting how much a simple color scheme change can make an app suddenly feel so much friendlier to me. 😌💗

treyhunner, to random
@treyhunner@mastodon.social avatar

@hugovk I found 2 differences in some (very in-the-weeds) Python Morsels exercises on Python 3.13.

I think the first might be a bug and the second is probably the result of fixing a bug.

https://pym.dev/p/35r3x/

Any thoughts on whether either might matter for production code? Or insight into the CPython issues/PRs that fixed these? (I did a quick search but couldn't figure it out)

Happy to report either difference in behavior, but I don't want to clutter up the issue tracker with noise.

hugovk,
@hugovk@mastodon.social avatar

@treyhunner Number 2 about locals() looks like intentional changes from PEP 667, see https://github.com/python/cpython/issues/118888 and https://github.com/python/cpython/pull/119201

I'm not sure about number 1, it's worth a new issue.

> Any thoughts on whether either might matter for production code?

Probably, see https://xkcd.com/1172/ !

Quality bug reports are always welcome. We want to find regressions, especially during the beta, and duplicate reports are better than none.

Thanks for testing the beta!

treyhunner,
@treyhunner@mastodon.social avatar

@hugovk thanks! I'll open an issue for the first one later. 👍

treyhunner, to python
@treyhunner@mastodon.social avatar

Note that this function uses an "if" statement that returns, and an "else" that also returns.

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

#Python #programming

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