3 ms·
Can someone direct me to a comparision of subprocess and os? I keep hearing subprocess is better, but have not really read any explanation as to why or when it
by wodenokoto 12y ago
Can someone direct me to a comparision of subprocess and os? I keep hearing subprocess is better, but have not really read any explanation as to why or when it is better.
(I'm glad I'm not the only one who was thrilled to discover enumerate()!)
- buttcoinslol 12y agoThe subprocess module is meant to replace a number of functions in the os module. The python documentation lists a number of examples here: https://docs.python.org/2/library/subprocess.html#subprocess-replacements https://docs.python.org/2/library/subprocess.html#subprocess... If you google 'os vs subprocess python' there are a few stackoverflow and quora threads comparing them.
- deleted 12y ago[deleted]
- crdoconnor 12y agoAll explained here: https://www.python.org/dev/peps/pep-0324/ https://www.python.org/dev/peps/pep-0324/ tl;dr * Security (including avoiding holes like shellshock) * Unification of process handling under one core library. * Easier detection of errors in processes. * Easier control of stderr/stdout. * Universal newline support. * Elimination of race conditions with .communicate()
- willvarfar 12y agoThe OS module interacts directly with the OS rather than abstracts it, so a lot of the functions in it have the "may not be available on all platforms" apology. Subprocess uses OS under the hood but offers an abstraction that mostly works on all platforms, e.g. the way that "communicate" is implemented on Windows differs considerably from how its implemented on Unix.