-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 回答