[Tutor] question on string

Alan G alan.gauld at freenet.co.uk
Mon Aug 1 23:05:17 CEST 2005


> I would like to construct some string objects using the 
> cprintf-style format:
>
> command_string = "diff -u %s %s > %s.patch" % ( src, dst, file )

Should work - assuming the 3 variables are defined! Although file
is a bad name for a variable since its also the name of the
function for opening files!

> 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.

What makes you think it is illegal? Did you get an error?
If so what did it look like (full text please).

> I have been looking and couldn't discover string constructor such as
>
> command_string = string( "diff -u %s %s > %s.patch" % ( src, dst, 
> file ) )

You don't need a constructor as such just use the quotes as in the 
first
attempt above.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld 



More information about the Tutor mailing list