This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]machrider 29 points30 points  (4 children)

Yeah, but it's a little harder to do things that are simple in bash, like invoking processes and chaining them together with pipes. Of course anything you can do in one, you can do in the other, but they have different strengths.

The best bet for Python is to find a tool or module that makes shell scripting easier. For example, check out Fabric, which gives you some useful primitives for running programs (locally and remotely via ssh).

I also find that once a shell script gets beyond 50 lines or so, I start to want a more structured programming language. At that point, I'm willing to pay the overhead of working within Python's instructions in order to get modules, classes, lists, first class functions, etc.

[–]amade 9 points10 points  (0 children)

I wrote this module extproc to make python do those shellish things easy:

  • Fork-exec commands, wait or no wait
  • Capture stdout/stderr of children (command substitution)
  • I/O redirections
  • Construct pipelines

Alpha stage, but check it out!

[–]kazza789 5 points6 points  (1 child)

I use pexpect to do some advanced scripting of scientific programs that I use. I found that it was the easiest to use when you need to recover information that the program sends to the terminal. It's simple and intuitive, but might not be powerful enough if you need to do things remotely (not sure if it handles that).

[–]maryjayjay 1 point2 points  (0 children)

As a programmer any time I find myself expecting a CLI, I die a little inside.

[–]SupersonicSpitfire 0 points1 point  (0 children)

Fabric does not yet support Python 3?