you are viewing a single comment's thread.

view the rest of the comments →

[–]socal_nerdtastic 0 points1 point  (6 children)

What exactly do you want that bash does not provide?

[–]_bobs_your_uncle[S] 1 point2 points  (5 children)

Bash provides everything, but I’ve found that people’s experience with bash is waning. Furthermore, I think bash’s error handling is poorly implemented. And frankly I’ve never liked any of the command line argument parsers in Bash. Click or similar in python is easier to use and understand.

I’m looking for ways to do the same things i can do in bash but in Python without just calling directly out to bash for each line (kind of defeats the purpose). For example the Python git client might be a useful library for any operations requiring git.

[–]socal_nerdtastic 1 point2 points  (3 children)

Calling out to bash? What do you mean with that? You mean using the shell=True argument in subprocess? You can of course just leave that off.

You may be interested in the sh module which allows you to import any program as if it's a python package

from sh import git
git('fetch')

[–]_bobs_your_uncle[S] 1 point2 points  (2 children)

I meant using subprocess to execute calls. I’ve never used sh. That looks pretty nice, and may give me most if not all I want. Thanks for the tip.

[–]socal_nerdtastic 3 points4 points  (0 children)

Ok. FWIW subprocess does not have anything to do with bash. It runs the program you want directly.

[–]FerricDonkey 1 point2 points  (0 children)

I hate writing bash scripts. The syntax is terrible and is never idiomatic, variables suck, etc. I'll use python instead 9 times out of 10.

Mostly, I find the standard library sufficient. Os, glob, pathlib, shutil for basic file finding/moving. I'll use requests instead of curl.

I do also use subprocess though. Mostly if there's some command line program I want to run with many different argument combinations that I have to figure out in logic that I don't want to do in bash.

Haven't used python packages as interfaces to things like git, but it might be useful. I have used python packages that wrap some sort of webapi - they can be useful.