CodeBron
CodeBron

Reputation: 25

ValueError: too many values to unpack (expected 2) when passing values from dictionary

I have a video_apps.json file that has a dictionary that contains a list of a list of two strings.

{ 
    "PROJECTS": {
        "A": [
            ["Csole/Viewer", "Csole/Viewer/Inc/Revision.h"],
            ["Csole/FPedal", "Csole/FPedal/Inc/Revision.h"]
        ],
        "B": [
            ["Hand/Label", "Hand/Label/Inc/Revision.h"],
            ["CSole/FController", "Csole/FController/Inc/Revision.h"]
        ]
    }
}

I created the following code block in my builder.py file to format the video_apps.json file so that I can store the value in PList.

        s_path = self._conf_dict["PATHS"]["LOCAL_IFORM_DIR"] + "/Fware/"
        self._fi_apps_list = []
        man_list = []

        for target, apps in self._fi_apps_dict["PROJECTS"].items():
            for app in apps:
                self._fi_apps_list.append(app[0])
                man_list.append(s_path + app[0] + "/Inc/Revision.h")
  
        PList = self._fi_apps_list, man_list
        create_table(PList)

If I'm correct, PList currently has the format: tuple[list, list]

I want PList to contain values as such:

PList = [("CSole/Viewer", "/home/user.com/src/iform/Fware/CSole/Viewer/Inc/Revision.h"),
               ("CSole/FPedal", "/home/user.com/src/iform/Fware/CSole/FPedal/Inc/Revision.h"),   
               ("Hand/Label", "/home/user.com/src/iform/Fware/Hand/Label/Inc/Revision.h"),
               ("Csole/FController", "/home/user.com/src/iform/Fware/Csole/FController/Inc/Revision.h")
                  ]

I get the following error when running the code block:

Traceback (most recent call last):
  File "build_fi.py", line 55, in <module>
    beta.test_function("config.json")
  File "/home/user.com/src/iform/dvops/build_iform_web/src/builder.py", line 178, in test_function
    create_table(ProjectList)
  File "/home/user.com/src/iform/dvops/build_iform_web/src/manifest.py", line 77, in create_table
    for (projectName, revisionHeaderPath) in PList:
ValueError: too many values to unpack (expected 2)
>>> stop/remove/kill container

To give some context, self._conf_dict["PATHS"]["LOCAL_IFORM_DIR"] + "/Fware/" in the code block is getting the user's path.

Any suggestions would be appreciated. Thank you for your help.

Upvotes: 0

Views: 265

Answers (1)

Barmar
Barmar

Reputation: 781210

You're making PList a tuple of lists. You want a list of tuples. Use zip() for that.

PList = list(zip(self._fi_apps_list, man_list))

Upvotes: 1

Related Questions