2 ms·
I really don't understand the "switch to Python" thing. Bash scripts are good for calling sequences of command line programs. That is not particularly convenien
by sanderjd 9y ago
I really don't understand the "switch to Python" thing. Bash scripts are good for calling sequences of command line programs. That is not particularly convenient in Python.
- icedchai 9y agoIt's perfectly convenient. The subprocess module works well enough for such things. Or even the old os.system.
- zippitydoodah68 9y agoPerfectly convenient, safe and fast. Pick any two. https://docs.python.org/2/library/subprocess.html https://docs.python.org/2/library/subprocess.html I've told developers that if I catch them writing shell scripts in python they must commit a shell script doing the same set of operations. 2x the work usually dissuades from this type of nonsense.
- icedchai 9y agoAs usual, "it depends." If you have complex logic, it's generally much cleaner to implement in python. (If you told me I had to rewrite a working Python script in shell, I'd probably think you were joking. Talk about nonsense.)
- zippitydoodah68 9y ago'It depends..' is a quagmire for the unwary. My route is to make a good rule about writing python with more than 'n' os., subprocess. and *.Popen calls automatically requiring shell script counterparts in case we find your need to pythonize unsafe, unreadable and slow|broken|buggy.
- icedchai 9y agoThere are obviously programs that are better written as a shell script, no denying it! I'm just saying use the best tool for the job. If you're writing complex logic in a shell script, you're probably barking up the wrong tree. Likewise, if all you're doing is calling external programs from python, you're probably doing it wrong.