Live data from Hacker News

I'm switching to Python and actually liking it

cesarsotovalero.net

611–620 of 718 posts

Re: I'm switching to Python and actually liking it

#611

Nice article, but this command doesn't activate the venv that's managed by uv. uv venv activate The command actually creates a new venv in a dir called "activate". The correct way to activate the venv is like this: source .venv/bin/activate

One of the key principles of uv is you don't activate the venv. You just run everything through uv every time, e.g `uv run pytest` or whatever.

Re: I'm switching to Python and actually liking it

#612

Out of curiosity, why would I use Dataclass vs a Pydantic Basemodel. If we did not have a PyDantic dependency I could imagine wanting to use Dataclass. But if I have it, why not use everywhere?

Unnecessary baggage if you don't need validation or serialisation. My rule of thumb is to use Pydantic if I need serialisation, otherwise I default to dataclasses.

This and not just for the performance reasons. A Pydantic model represents an I/O boundary of a program. This conveys a lot of information to a programmer reading the code. It would be quite misleading to find it's actually only passed around internally and never used for I/O. A bit like using an int type to store a Boolean value.

On the other hand if I see a dataclass I can tell what it's purpose is by whether it's frozen or not etc.

Always strive for self-documenting code.

Re: I'm switching to Python and actually liking it

#613
If you're working on machine learning the most economic choice is Python.

But weiting a processing pipeline with Python is frustrating if you have worked with C# concurrency.

I figured the best option is Celery and you cannot do it without an external broker. Celery is a mess. I really hate it.

Re: I'm switching to Python and actually liking it

#614

Earlier quoted context omitted.

That's kind of the point. These methods are never meant to be called directly. They're used to desugar. I think it's fairly short sighted to criticize these. FWIW, I also did that the first time I wrote Python. Other languages that do similar things provide a useful transparency.

I don’t think anyone is criticizing its utility, just that the syntax of 2-5(?) underscores in a row isn’t something that is DX friendly.

They are called dunder methods, meaning "double under". It's 2 underscores.

I've had snippets in my editor for approximately 15 years at this point so I don't have to manually type any of the dunder methods. Would recommend!

Re: I'm switching to Python and actually liking it

#615

When did Python go out of fashion? This is the second article I've seen talking about it as if it's some kind abomination. I get that it's not the shiny new thing, but I don't understand people hating on it. Is this just junior devs who never learned it, or is there some new language out that I missed? (And please don't tell me Javascript....)

It's not out of fashion. We're just seeing the long tail finally picking it up. It's becoming somewhat of a lingua franca of programming.

Re: I'm switching to Python and actually liking it

#616
post #287

> I would like to have a tool that generates the project structure for me, but I haven’t found one that fits me yet. I recommend cookiecutter for this. I have a few templates I've built with that which I use frequently: python-lib: https://github.com/simonw/python-lib click-app: https://github.com/simonw/click-app datasette-plugin: https://github.com/simonw/datasette-plugin llm-plugin: https://github.com/simonw/llm-p…

I looked at the click-app repo. If you were creating that today, would you switch from uv to pip?

And to run cookiecutter do you still use pipx, or have you switched to `uv tool install`

Re: I'm switching to Python and actually liking it

#617

Python has done an impressive job over the years of making steady robust improvements. The typing and tooling has just gotten better and better. There are still plenty of problems though, imho async is still a much bigger pain than it should be (compared to other runtimes with a very nice experience like go or elixir, even dotnet has been less pain in my experience). Overall I like python, but it mainly boils down to…

It's quite crazy, as Python first version was in 1991, 4 years before Java. It's a language with a ton of legacy baggage, the 2/3 transition, the BDLF being replaced by a completely different project leadership system, and it still keeps going strong.

This interview from Brett Cannon (old core dev who worked on packaging, imports, the vscode python extension...) is eye opening:

https://www.bitecode.dev/p/brett-cannon-on-python-humans-and

The guy cares SO MUCH and they have so many things not to break you can feel the sense of passion and the weight of responsibility in everything he says.

Re: I'm switching to Python and actually liking it

#618
post #429

Earlier quoted context omitted.

You don't generally want API keys accidentally recorded into someone's bash history.

What exactly is your threat model, where the attacker can read ~/.bash_history but can't execute (or capture output from) /usr/bin/env?

CI and other build systems. Where tokens have been stolen in the past, by users not caring, and a VM not being properly cleaned.

Re: I'm switching to Python and actually liking it

#619
post #80

Just a small note on the code in the linked script: API_KEY = os.environ.get("YOUTUBE_API_KEY") CHANNEL_ID = os.environ.get("YOUTUBE_CHANNEL_ID") if not API_KEY or not CHANNEL_ID: print("Missing YOUTUBE_API_KEY or YOUTUBE_CHANNEL_ID.") exit(1) Presenting the user with "Missing X OR Y" when there's no reason that OR has to be there massively frustrates the user for the near zero benefit of having one fewer if statemen…

I usually go through an array of settings that must be defined and list any missing ones, to avoid repeated attempts from the user/deployer.

Re: I'm switching to Python and actually liking it

#620
post #396

Funnily enough, I made the opposite switch recently, and am also liking it. My thoughts about python here: https://calvinlc.com/p/2025/06/10/thank-you-and-goodbye-pyth... Next time I get into Python I’ll try uv, ruff, ty.

ty is still in alpha, I wouldn't recommend it yet. It's fast but has many false positives. In the words of charlie himself: https://bsky.app/profile/crmarsh.com/post/3lp2xikab222w

uv + ruff (for formatting AND linting) is a killer combo, though.

And the more you use uv, the most you discover incredible stuff you can do with it that kills so many python gotchas like using it in the shebang with inline deps or the wonders of "--with":

https://www.bitecode.dev/p/uv-tricks

Post reply on HN