0

I'm trying to map a json file to a python object based on this solution.
The code I tried to write is the following:

from json import loads
from collections import namedtuple
from os import path

class CamConfigurator:
    with open(path.join('utility', 'cam', 'configurator.json')) as __configFile:
        __configurator = loads(
            __configFile,
            object_hook=lambda dictonary: namedtuple(
                'X', dictonary.keys()
            )(*dictonary.values())
        )
    camIndex = __configurator.availableCams[-1]
    pathToSnapshots = __configurator.pathToSnapshots

The error that came out is the following:

TypeError: expected string or buffer

Memmo
  • 298
  • 3
  • 8
  • 31

1 Answers1

0

Add .read() to the first loads input:

from json import loads
from collections import namedtuple
from os import path


class CamConfigurator:
    with open(path.join('utility', 'cam', 'configurator.json')) as __configFile:
        __configurator = loads(
            __configFile.read(), # <- there
            object_hook=lambda dictonary: namedtuple(
                'X', dictonary.keys()
            )(*dictonary.values())
        )
    camIndex = __configurator.availableCams[-1]
    pathToSnapshots = __configurator.pathToSnapshots
Memmo
  • 298
  • 3
  • 8
  • 31