user1008855
user1008855

Reputation: 23

Writing 4 arguments with the write function to a file

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

Answers (2)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

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

Greg Hewgill
Greg Hewgill

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

Related Questions