我通过更改目录中的每个文件而收到此错误

时间:2019-12-06 07:08:22

标签: python json python-3.x

由于某种原因,在某些事情可以解决之前,我遇到了一个错误。有人可以告诉我这是什么问题。

    import os
    import json
    for filename in os.listdir(os.getcwd()):
        print(filename)
        if '.json' in filename:
            with open(filename, 'w') as y:
                filename = filename[:-5]
                json.dump({
                    "parent": "item/generated",
                    "textures": {
                        f"item/guildinterface/{filename}"
                    }

                }, y)


if __name__ == '__main__':
    main()

错误是

  File "C:/Heights/Documents/Projects/yotam/3.7/plutto/test.py", line 19, in <module>
    main()
  File "C:/Heights/Documents/Projects/yotam/3.7/plutto/test.py", line 15, in main
    }, y)
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python37-32\lib\json\__init__.py", line 179, in dump
    for chunk in iterable:
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python37-32\lib\json\encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python37-32\lib\json\encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python37-32\lib\json\encoder.py", line 438, in _iterencode
    o = _default(o)
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python37-32\lib\json\encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type set is not JSON serializable

0 个答案:

没有答案