Live data from Hacker News

Using Python for Scripting

hypirion.com

21–30 of 112 posts

Re: Using Python for Scripting

#21
post #5

Earlier quoted context omitted.

Well, that's kind of what I mean. For scripts in a python project, you can freely use whatever packages you need. But for one-off scripts, if you need bs4 or something, you're screwed. Either your script now has external dependencies or it requires special tooling. It just feels strange that C# of all languages is now a better scripting tool than Python, at least out of the box. I did notice uv has exactly the featur…

I don't understand. To return to GP's point, what can you do in bash that you can't do in Python? Said in another way, what does bash offer that you would need to tackle with a dependency in Python? My understanding is that there is no such thing, and accordingly, you can still end up with something that is better than bash if you just use Python and call out to other tools with subprocess.

There's bash. Then you need better loops/conditionals and more usable structures. That's when one should think of using a scripting language instead. I think the parent goes too far after that and what he's talking about is not something bash can do (well).

That said, a lot of very complicated things are actually written in bash. Distrobox I think is for example.

Re: Using Python for Scripting

#23
I've never liked shell scripting. Last year, I switched my build system of a Rust project over to Python (Cargo is actually quite limited as a build system). For a newer project, I'm using Rust itself with the XTask pattern. I'm not sure if I prefer the Python or Rust approach yet.

Re: Using Python for Scripting

#24
post #10

Earlier quoted context omitted.

You can specify requirements at the top of file and uv can run the script after automatically installing the dependencies. https://avilpage.com/2025/04/learn-python-uv-in-100-seconds....

This works really well in my experience, but it does mean you need to have a working internet connection the first time you run the script. # /// script # dependencies = [ # "cowsay", # ] # /// import cowsay cowsay.cow("Hello World") Then: uv run cowscript.py It manages a disposable hidden virtual environment automatically, via a very fast symlink-based caching mechanism. You can also add a shebang line so you can ex…

I wish env -S was more portable. It's a newer feature of the coreutils env implementation and isn't supported elsewhere afaik.

Re: Using Python for Scripting

#25
post #24
post #10

Earlier quoted context omitted.

This works really well in my experience, but it does mean you need to have a working internet connection the first time you run the script. # /// script # dependencies = [ # "cowsay", # ] # /// import cowsay cowsay.cow("Hello World") Then: uv run cowscript.py It manages a disposable hidden virtual environment automatically, via a very fast symlink-based caching mechanism. You can also add a shebang line so you can ex…

I wish env -S was more portable. It's a newer feature of the coreutils env implementation and isn't supported elsewhere afaik.

FreeBSD 6.0 added 'env -S'. They have adopted a few different GNU inspired options recently, which I am happy about.

Re: Using Python for Scripting

#26
post #3

How do you handle packages? I want scripts to a be a single file with a shebang, not a repo with a requirements.txt that I need to run in a venv. To me, this is the biggest blocker to using Python for any non-trivial scripting (which is precisely the kind where I wouldn't want to use bash), but I'd like to know how others deal with it. C# scripts let you reference packages in a comment at the top of the file, for exa…

What is wrong with writing a short wrapper in bash to activate a conda env before running the script? Too unsexy?

Re: Using Python for Scripting

#27
post #5

Earlier quoted context omitted.

Well, that's kind of what I mean. For scripts in a python project, you can freely use whatever packages you need. But for one-off scripts, if you need bs4 or something, you're screwed. Either your script now has external dependencies or it requires special tooling. It just feels strange that C# of all languages is now a better scripting tool than Python, at least out of the box. I did notice uv has exactly the featur…

UV is taking over really fast, it seems to be much more popular any other option. I suspect conda still has some market share too but I've never needed it.

It's amazing what happens when something just works.

Re: Using Python for Scripting

#30
post #3

How do you handle packages? I want scripts to a be a single file with a shebang, not a repo with a requirements.txt that I need to run in a venv. To me, this is the biggest blocker to using Python for any non-trivial scripting (which is precisely the kind where I wouldn't want to use bash), but I'd like to know how others deal with it. C# scripts let you reference packages in a comment at the top of the file, for exa…

> How do you handle packages? The same way you handle them with bash? Install them? What are we talking about here?

I think it is the fact that python packaging has been problematic for some time. setuptools/easy_install, pip/pipx, poetry, conda, uv all promise they will be the thing that "fixes" it
Post reply on HN