converting from shell script to python

Greg Ewing (using ckea25d02 at
Wed Apr 2 02:40:38 CEST 2003

Mathias Waack wrote:
> import os
> ROOTDIR='/usr/lib'
> CLASSPATH="%s/a/a.jar:%s/b/b.jar:%s/c/c.jar" % \
> os.system('java -classpath %s foo' % (CLASSPATH))

Alternatively, you can substitute things from a
dictionary instead of a tuple:

   vars = {'ROOTDIR': '/usr/lib'}
     "%{ROOTDIR}s/a/a.jar:%{ROOTDIR}s/b/b.jar:%{ROOTDIR}s/c/c.jar" % vars

That technique can be more readable if you have
more variables that you want to substitute into
the string, since you can name them where they're
used instead of relying on positional matching.

Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand

More information about the Python-list mailing list