bash Vs python ??

Yu Wang Yu.Wang at synopsys.COM
Wed Nov 5 20:32:15 EST 2003


In my experience, for "automated some scripts" less than 50 lines, no 
heavy file handling, bash is more suitable. Otherwise, Python wins.
You can write rather faster if the script is composed of different "call 
commands" in bash. But if you have to deal with intermediate file/string 
, to use bash is a pain. I always change to Python.
Afterwise, everything you can use in bash, you can find certain ways in 
Python.

Ville Vainio wrote:
> William Park <opengeometry at yahoo.ca> writes:
> 
> 
>>It depends.  My guess is Bash would be more suitable for "automated
>>testing scripts", since you'll be calling lots of utilities.
> 
> 
> os.system, os.popen family, pexpect...
> 
> In python it's much easier to process the output and produce the input
> of the utilities.
> 
> Bash is good for throwaway one liners, Python is good for scripts that
> you *gasp* save to a file and might also execute later. You never
> know, you might want to extend the testing system later on, perhaps
> developy advanced logging facilities etc. 
> 
> The shell has one advantage over Python, though: it can be executed in
> the environment of current shell (i.e. '. myscript.sh'), so you can
> change the environment variables in the surrounding environment. In
> python you would have to do 
> 
> export MYENVVAR = $(python calcvalforvar.py)
> 
> If that is what you need, you might want to use bash. Otherwise, use
> python. And even if you need that, you might want to generate the bash
> script in a python script.
> 
> A good rule of thumb is: The less non-python stuff you have around,
> the better. Non-python parts of any given system are invariably the
> ones causing most of the problems :-).
> 






More information about the Python-list mailing list