Subprocess without the shell

Back to list2026-08-25
You

Is shell=True ever acceptable?

ChatGPT

When the command genuinely is a shell pipeline you control end to end, and never with any value that came from outside the program. The list form avoids quoting entirely, which is both safer and easier to read.

You

How do I structure a file that is both a module and a CLI?

ChatGPT

Keep the work in functions, put argument parsing in main(), and guard with if __name__ == "__main__": sys.exit(main()). Return codes from main then work for both the shell and the tests.