> Python is installed on pretty much every machine > Python 3 is installed on basically every machine out there. > Python will work the same on all the machines you run your script on No, no, and no.
Using Python for Scripting
41–50 of 112 posts
Re: Using Python for Scripting
#42Earlier quoted context omitted.
Nix allows you to do this with any language and required dependency: https://wiki.nixos.org/wiki/Nix-shell_shebang
Whoa! This is a revelation. I already loved Nix and used nix-shell extensively, but this is the missing piece: fully reproducible Python scripts without compromise.
Then you can do e.g. use other persons python scripts without modifying their shebang.
Re: Using Python for Scripting
#43> By the way, don’t add a comma after the elements in the list, ... Python: forty_two = ( 42 ) tuple_containing_forty_two = ( 42, )
42,
This expression is a tuple all by itself.Re: Using Python for Scripting
#44Pretty much anything longer then a throwaway one liner I write in python. Would be cool if python had a pipe operator though. The back ticks in ruby is pretty ergonomic too. Wish python had a simpler way to run commands. Kind of tedious to look up subprocess run arguments and also break things up into arrays.
For example,
subprocess.run(“rm -rf ~/ some file”, shell=True)
and subprocess.run([“rm”, “-rf”, “~/ some file”])
have significant different behavior.Re: Using Python for Scripting
#45Earlier 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....
As someone who writes a lot of python, I love uv, but isn't on nearly every system like python is, which is one of the arguments for using python here in the first place
If you are installing packages, then starting with installing uv should be fine.
Re: Using Python for Scripting
#46How 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…
Nix allows you to do this with any language and required dependency: https://wiki.nixos.org/wiki/Nix-shell_shebang
Might as well rewrite all your scripts in Rust too while you're layering on unholy amounts of complexity.
Re: Using Python for Scripting
#47How 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…
once the script is non-trivial, 'install' it using pipx, in editable mode when you work on the script and as normal pipx installed cli utility otherwise.
the venv part is then completely under the hood.
Re: Using Python for Scripting
#48Re: Using Python for Scripting
#49Re: Using Python for Scripting
#50I'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.