Bash vs Python

30 Jun 2010

by hemanth

A simple case study:
It's not about one programming language killing and replacing the other, its all about the purpose!

The scenario:
Using convert to resize images, both in bash and python just for the fun of it.

First up is BASH:

mkdir -p resized
find . -name '*.jpg' -or -name '*.png' -or -name '*.gif'\
-exec  convert -resize 648x480 '{}'\
"resized/$(basename '{}')" ';'

Its Pythons turn:

from glob import glob
from os.path import splitext
from os import system
if not path.exists('resized'):
mkdir('resized')
for pic in glob.glob('*'):
if os.path.splitext(pic)[1] in ext:
system('convert -resize 640x480 "%s" "resized/%s"'
% (pic,os.path.splitext(pic)[0]))
Share this