4
$\begingroup$

I'm getting this error come up on this line of code, that was working fine in 2.9+ but now isn't for 3.0

path = bpy.utils.user_resource('SCRIPTS', os.path.join("presets", "keyconfig"), create=False) 

The error: TypeError: user_resource() takes 1 positional argument but 2 positional arguments (and 1 keyword-only argument) were given

I'm seeing this exact error mentioned on Stackoverflow, but failing to understand it or how it works in the Blender environment.

$\endgroup$
2
  • 2
    $\begingroup$ Use a keyword arg for the path like you do for create: path=os.path,join(...). See this Q. $\endgroup$
    – scurest
    Commented Dec 6, 2021 at 20:55
  • $\begingroup$ Fantastic @scurest, thank you! $\endgroup$
    – Increality
    Commented Dec 6, 2021 at 21:03

1 Answer 1

5
$\begingroup$

If you compare the old docs with the new docs:

bpy.utils.user_resource(resource_type, path='', create=False)
bpy.utils.user_resource(resource_type, *, path='', create=False)

You will see an asterisk appeared. It means, that from this point forward, all arguments have to be passed as keyword arguments. So path no longer can be passed as a positional argument, you need to change:

path = bpy.utils.user_resource('SCRIPTS', os.path.join("presets", "keyconfig"), create=False)

to

path = bpy.utils.user_resource('SCRIPTS', path=os.path.join("presets", "keyconfig"), create=False) 

Bare asterisk in function arguments?

$\endgroup$
2
  • 1
    $\begingroup$ Thank you for the thorough explanation! $\endgroup$
    – Increality
    Commented Dec 6, 2021 at 21:32
  • 2
    $\begingroup$ Note: If you check the release notes There is a fairly long list of methods that now require keyword arguments. $\endgroup$ Commented Dec 6, 2021 at 23:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .