<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Thank you all for the enthusiastic responses. It must have been other
part of the script since the command string construction now works. I
also realized that "file" is a poor choice of variable name. Thanks
Danny for telling me about the subprocess module.<br>
<br>
Best regards, Gilbert.<br>
<br>
<br>
ZIYAD A. M. AL-BATLY wrote:
<blockquote cite="mid1122921585.16017.5.camel@localhost.localdomain"
type="cite">
<pre wrap="">On Mon, 2005-08-01 at 10:42 -0700, Gilbert Tsang wrote:
</pre>
<blockquote type="cite">
<pre wrap="">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.
</pre>
</blockquote>
<pre wrap=""><!---->"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.
</pre>
</blockquote>
<br>
</body>
</html>