Live data from Hacker News

I'm switching to Python and actually liking it

cesarsotovalero.net

561–570 of 718 posts

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

#561

Earlier quoted context omitted.

I was talking about pip, not venv. I don't use venv either, not because I think it's a bad idea but because I can't be bothered. Stuff does end up conflicting unless I use Docker (lol) or uv.

If you use uv you are using virtual environments . You're merely being shielded from a few minutes worth of education about how they work ( https://chriswarrick.com/blog/2018/09/04/python-virtual-envi... ).

Well I also don't have to deal with the venv then, uv does it for me. Which I suspected is how it works, cause idk how else it would.

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

#562
post #172

Earlier quoted context omitted.

I write a decent amount of Python, but find the walrus operator unintuitive. It's a little funky that API_KEY is available outside of the `if`, perhaps because I had first seen the walrus operator in golang, which restricts the scope to the block.

This isn't really unique to the walrus operator, it's just a general python quirk (albeit one I find incredibly annoying). `for i in range(5): ...` will leave `i` bound to 4 after the loop.

> `for i in range(5): ...` will leave `i` bound to 4 after the loop. reply

This "feature" was responsible for one of the worst security issues I've seen in my career. I love Python, but the scope leakage is a mess. (And yes, I know it's common in other languages, but that shouldn't excuse it.)

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

#563
post #483
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…

why print then exit(1) instead of raising an exception?

Oh, I know this one:

  $ python3 -c "print('clear messaging'); exit(1)"
  clear messaging

  $ python3 -c "raise ValueError('text that matters')"
  Traceback (most recent call last):
    File "", line 1, in 
  ValueError: text that matters
and that story gets _a lot_ worse when some programs raise from within a "helper" module and you end up with 8 lines of Python junk to the one line of actual signal

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

#564
post #541
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…

Or API_KEY = os.environ.get("YOUTUBE_API_KEY") CHANNEL_ID = os.environ.get("YOUTUBE_CHANNEL_ID") assert(API_KEY, "Missing YOUTUBE_API_KEY") assert(CHANNEL_ID, "Missing CHANNEL_ID")

Do you use parens with assert? In Python, the assert statement is not a function, right?

That bit me before... it created a tuple which evaluated as true.

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

#565
post #522

> So yeah, Python is powerful, and it couples very well with the now ubiquitous VSCode editor. I always found vscode lacking for Python and C compared to pycharm and clion. The latter just work without fiddling with config files.

Funny enough I feel the other way about JetBrains IDEs. They * seem * super powerful, but there is always a lot of config that needs to go into them if I'm doing app, infra, and pipeline work. (Edit, not saying they aren't powerful, just more that as coming into them I'm never sure how to wield it the best out of the box) In my experience (not saying this is universal), the folks that like JetBrains IDEs came from ja…

The things that just work that I look for are mouseover to get info on an identifier (local or external), right click to go to the definition, and running code in the debugger with a click. Maybe I just don’t know how to set that up in vscode; I’m a company of one and don’t have a coworker to ask how to do it. My Python work was just making requests, analyzing the data and outputting results to csv’s. This was replaced by Rust and then C. And the C is 60k loc as it does much more. In Clion when you open a cmake project it automatically understands your project structure from the cmake files and provides those need-to-have features I listed.

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

#566

> Not only because the syntax is more human-friendly, but also because the Python interpreter is natively integrated in all Unix distros That's kind of very optimistic evaluation - literally anything beyond "import json" will likely lead you into the abyss of virtual envs. Running something created with say Python 3.13.x on Ubuntu 22.04 or even 24.04 (LTSs) / Rocky 9 and the whole can of worms opened. things like vir…

+1 - I've been shocked at how many little portability issues that I've had shipping software, even within the relatively constrained environment of fellow employees.

Minor differences between distro versions can make a big difference, and not everyone that uses a Python script knows how to use something like pyenv to manage different versions.

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

#567

Earlier quoted context omitted.

I find it incredibly intuitive and useful that it does that. sometimes it drives me nuts that it doesn't do it for comprehensions but I can see why. But if something fails in a loop running in the repl or jupyter I already have access to the variables. If I want to do something with a loop of data that is roughly the same shape, I already have access to one of the the items at the end. Short circuiting/breaking out o…

Python 2 actually did let comprehension variables leak out into the surrounding scope. They changed it for Python 3, presumably because it was too surprising to overwrite an existing variable with a comprehension variable.

That almost sounds like having the "variables" eax, ebx, ecx, and edx.

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

#568
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?

Threat model: shell scripts

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

#569

> Not only because the syntax is more human-friendly, but also because the Python interpreter is natively integrated in all Unix distros That's kind of very optimistic evaluation - literally anything beyond "import json" will likely lead you into the abyss of virtual envs. Running something created with say Python 3.13.x on Ubuntu 22.04 or even 24.04 (LTSs) / Rocky 9 and the whole can of worms opened. things like vir…

More like a snake pit than a can of worms.

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

#570

Earlier quoted context omitted.

Millions of people put it into Docker, or they just deal with it and you see the results with tons of Stackoverflow questions

> Millions of people put it into Docker, or they just deal with it and you see the results with tons of Stackoverflow questions Arrogantly wrong. I've coded in Python for almost 20 years. Many of those years I've had it as my primary language at work. 2024 was the first year I actually needed a virtualenv. Before that, I'd happily use pip to install whatever I want, and never had a version conflict that caused proble…

Some packages are written by researchers in fields that aren’t engineering. Sometimes you go all the way and reach for a VM.
Post reply on HN