For a loop error when accessing the Dict element: the 'dict' object is not callable

advertisements

I've looked at 'dict' object is not callable SO answers but don't quite see what I am messing up.

I have an array of dictionaries and then I want to go through each one and access the elements.

prebuilt_jars = [
{'name':'xwalk-app-jar', 'binary_jar':'xwalk_core_library/libs/xwalk_core_library_java_app_part.jar'},
]

for prebuilt_jar in prebuilt_jars:
  prebuilt_jar(
    name = prebuilt_jar['name'],
    binary_jar = prebuilt_jar['binary_jar'],
  )
  jar_deps.append(':' + prebuilt_jar['name'])

However I am getting a 'dict' object is not callable on

name = prebuilt_jar['name'], and

binary_jar = prebuilt_jar['binary_jar'],

Do you know what is wrong with my syntax?

Update

So what I am doing is trying to condense a whole bunch of rules I have like this:

prebuilt_jar(
  name = 'xwalk-app-jar',
  binary_jar = 'xwalk_core_library/libs/xwalk_core_library_java_app_part.jar',
)

jar_deps.append(':xwalk-app-jar')

prebuilt_jar is a Buck function that builds a prebuilt jar file.

I want to instead have a dictionary of all my jar objects, and then loop that using those dictionary objects to populate the prebuilt_jar call.

Answer

I named the loop variable the same as the function name.

for pJar in prebuilt_jars:
  prebuilt_jar(
    name = pJar['name'],
    binary_jar = pJar['binary_jar'],
  )
  jar_deps.append(':' + pJar['name'])


This is, quite literally, a function call syntax on the loop variable:

prebuilt_jar(
    name = prebuilt_jar['name'],
    binary_jar = prebuilt_jar['binary_jar'],
  )

What is your intent with that code?

I'd imagine that this:

for prebuilt_jar in prebuilt_jars:
  jar_deps.append(':' + prebuilt_jar['name'])

is what you meant.