Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you code in Python, your probably should use the language as much as possible and avoid calling shell commands.

E.G:

- manipulate the file system with pathlib

- do hashes with hashlib

- zip with zipfile

- set error code with sys.exit

- use os.environ for env vars

- print to stderr with print(..., file=...)

- sometimes you'll need to install lib. Like, if you want to manipulate a git repo, instead of calling the git command, use gitpython (https://gitpython.readthedocs.io/en/stable/)

But if you don't feel like installing a too many libs, or just really want to call commands because you know them well, then the "sh" lib is going to make things smoother:

https://pypi.org/project/sh/

Also, enjoy the fact Python comes with argparse to parse script arguments (or if you feel like installing stuff, use typer). It sucks to do it in bash .

If what you need is more build oriented, like something to replace "make", then I would instead recommend "doit":

https://pydoit.org/

It's the only task runner that I haven't run away from yet.

Remember to always to everything in a venv. But you can have a giant venv for all the scripts, and just she-bang the venv python executable so that it's transparent. Things don't have to be difficult.

Finally, sometimes it's just easier to do things in ipython directly. Indeed, with a good PYTHONSTARTUP script, you don't have to import everything, you get superb completion+help, and you can call any bash command by just doing "!cmd". In fact, the result can be store in a python variable. Also you can set autocall so that you don't have to write parenthesis in simple function calls.



Is this satire?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: