-1
def __init__(self, dictionary_paths):
    files = [open(path, 'r') for path in dictionary_paths]
    dictionaries = [yaml.load(dict_file) for dict_file in files]
    map(lambda x: x.close(), files)
    self.dictionary = {}
    self.max_key_size = 0
    for curr_dict in dictionaries:
        for key in curr_dict:
            if key in self.dictionary:
                self.dictionary[key].extend(curr_dict[key])
            else:
                self.dictionary[key] = curr_dict[key]
                self.max_key_size = max(self.max_key_size, len(key))
    self.dictionary[key] = curr_dict[key]

結果は

TypeError: string indices must be integers, not str

修正方法は?

4

1 に答える 1

1

問題は、curr_dictその名前が意味するものにもかかわらず、それは文字列であり、辞書ではないということです。

In [6]: 'abc'['x']

TypeError: string indices must be integers, not str
于 2013-02-13T18:27:23.160 に答える