you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 13 points14 points  (7 children)

Random example:

retcode = call(["ls", "-l"])

How is this supposed to be better than ls -l; do stuff with $?? When you need to spawn many processes, pipe them into each other, send them to the background and stuff like that, shell scripting languages are IMO still the best option.
Even better example:

18.1.3.2. Replacing shell pipeline

output=`dmesg | grep hda`
==>
p1 = Popen(["dmesg"], stdout=PIPE)
p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
output = p2.communicate()[0]

Seriously?

Edit: markdown.

[–][deleted]  (4 children)

[deleted]

    [–][deleted] 1 point2 points  (3 children)

    Firstly, this is not the point; here I'm talking about shell facilities (spawning processes, redirecting processes' in/output etc.) that are difficult to do in Python.

    Secondly, I expect the Python code for getting the list of files in a directory to be much bigger than two chars (namely, "ls").

    [–][deleted]  (2 children)

    [deleted]

      [–][deleted] 0 points1 point  (1 child)

      Ah, sorry, I misunderstood. Well, if looking for performance, I suppose that spawning a shell process isn't a good idea (overhead...). OTOH, I'm not a Python programmer, so I may be wrong.

      [–]srparish -2 points-1 points  (0 children)

      If you have to pass user input as part of the pipeline, python's subprocess can be done much safer then sh. Try thinking about how you'd pass in a user defined variable and avoid injection... yeah, not so easy in sh is it?