Reputation: 23
I would like to write this to a file f.write("add unit at-wc 0 0 0 %s" % x ,y, z, "0.000 0.000 0.000 ")
but when I do that I get an error saying function takes exactly 1 argument (4 given).
Upvotes: 1
Views: 10896
Reputation: 798706
%
has higher precedence than ,
.
f.write("add unit at-wc 0 0 0 %s" % (x, y, z, "0.000 0.000 0.000 "))
But now you'll get a different error since you have more values than placeholders.
Upvotes: 1
Reputation: 993213
You're using the %
operator incorrectly. You might be looking for something like this:
f.write("add unit at-wc 0 0 0 %s %s %s 0.000 0.000 0.000 " % (x, y, z))
Notice that the substitution variables x, y, z
are all in parentheses, which means they are a single tuple passed to the %
operator.
In your code, notice how you have four parameters to the write()
function (I've put each parameter on a separate line to make it easier to see):
f.write(
"add unit at-wc 0 0 0 %s" % x,
y,
z,
"0.000 0.000 0.000 "
)
Upvotes: 6