[Tutor] question on string
ZIYAD A. M. AL-BATLY
zamb at saudi.net.sa
Mon Aug 1 20:39:45 CEST 2005
On Mon, 2005-08-01 at 10:42 -0700, 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.
>
> I have been looking and couldn't discover string constructor such as
>
> command_string = string( "diff -u %s %s > %s.patch" % ( src, dst, file ) )
>
> From the documentation on docs.python.org, the closest is string
> Template (but my python installation doesn't come with this module). Any
> insights on initializing string in this manner?
>
>
> Thanks, Gilbert.
"file" is a reserved word! This is why it's not working for you!
Change "file" to something else, like "result" for example.
Here:
>>> src = 'file1.c'
>>> dst = 'file2.c'
>>> result = "result"
>>> command_string = "diff -u %s %s > %s.patch" % (src, dst, result)
>>> command_string
'diff -u file1.c file2.c > result.patch'
Is this what you want?
Ziyad.
More information about the Tutor
mailing list