this post was submitted on 25 Aug 2023
737 points (87.3% liked)

Programmer Humor

32557 readers
595 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] dandroid@dandroid.app 12 points 1 year ago (3 children)

Do you do any scripts beyond extremely simple ones?

I do a fuck ton of scripting in both bash and python. I never want to do string manipulation in bash. As soon as string manipulation is required, I automatically choose python for a script. Also, if I need named arguments or multiple levels of arguments for subcommands. You can use sys.argv for basic args, which isn't any harder than bash arguments, but for complex inputs, argparse is a godsend. It has a bit of a learning curve, but it can handle anything. Bash requires you to write complex arg handling manually with loops and reducing.

[–] Redscare867@lemmy.ml 6 points 1 year ago (1 children)

You should check out Click. Way more user friendly than argparse imo. I agree with all of your points though, and I’d also add if you are working on a team that it will be infinitely easier for a co-worker to decipher your python code compared to a bash script. And you can write unit tests with py test, the list goes on and on. If the environment you are deploying to has the python interpreter, you should use python over bash.

[–] dandroid@dandroid.app 3 points 1 year ago

I'll take a look at Click. Something better than argparse definitely piques my interest, because while the features are great, it feels a little cumbersome at times.

[–] Gork@lemm.ee 3 points 1 year ago

I'm trying to bash it but the problem persists. Please help.