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.
Best regards, Gilbert.
ZIYAD A. M. AL-BATLY wrote:
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 = ''
>>> 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.
|
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor