I want to add a driver to the Z location of an object via python.
After reading the docs and this question, I would guess something like this:

bpy.context.object.driver_add("location", index=2)

However when run in the python console it says

Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
TypeError: driver_add() takes no keyword arguments

1 Answer 1


The error message gives a hint:

TypeError: driver_add() takes no keyword arguments

So pass the index as positional argument:

bpy.context.object.driver_add("location", 2)

  • $\begingroup$ Ah, thanks. Is it a mistake in the docs then that the keyword is included? $\endgroup$
    – gandalf3
    Dec 28, 2014 at 10:02
  • 2
    $\begingroup$ It is confusing. The python api documentation uses templates provided by sphinx. This notation indicates that the second parameter is optional and also specifies its default value. An annotation that no keyword arguments are allowed should be added. $\endgroup$ Dec 28, 2014 at 10:19
  • $\begingroup$ @pinkvertex Thanks, your comment explains why the BGE docs are like that. $\endgroup$
    – David
    Dec 28, 2014 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.