python along or bash combined with python (for manipulating files)

samwyse samwyse at gmail.com
Tue Oct 13 23:01:07 EDT 2009


On Oct 13, 9:13 pm, Peng Yu <pengyu... at gmail.com> wrote:
> Bash is easy to use on manipulating files and directories (like change
> name or create links, etc) and on calling external programs. For
> simple functions, bash along is enough. However, bash does not support
> the complex functions. Python has a richer library that could provide
> support for complex functions (such compute the relative path between
> two paths).
>
> I'm wondering for a task that can not be done with bash along whether
> it would be better to do in pure python or with a mix of both python
> and bash. What I care is mostly coding speed and a little bit
> maintainability (but not much). Can somebody provide some experience
> on when to combine python and bash and when to use pure python?

Scripting languages try to optimize gluing disparate programs together
to accomplish a task; bash excels at this.  Programing languages try
to optimize finding the solution to a problem; Python excels at this.

Generally, I try to stick to one language per problem, be it bash, C+
+, Java, Perl or Python.  Bash scripts translate easily into the
others, so you don't lose much time if you decide you started with the
wrong language.

Countering that, I also maintain a "toolbox" of programs that I can
call upon when needed.  In those cases, I don't hesitate to call a
program that I've written in any language from a bash script.

BTW, I actually prefer ksh to bash, but YMMV.



More information about the Python-list mailing list