Gilbert Tsang wrote: > Hi there, > > I would like to construct some string objects using the cprintf-style > format: > > command_string = "diff -u %s %s > %s.patch" % ( src, dst, file ) > > Of course it is illegal in python but I couldn't figure out a way to > construct strings with that kind of formatting and substitution.
Actually that is correct as written! (though 'file' is a poor choice of variable name as it shadows the built-in file() function...) >>> src = 'mySource' >>> dst = 'myNewSource' >>> file = 'diff.out' >>> command_string = "diff -u %s %s > %s.patch" % ( src, dst, file ) >>> command_string 'diff -u mySource myNewSource > diff.out.patch' See http://docs.python.org/lib/typesseq-strings.html for details on string formatting. Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor