AttributeError

python笔记:

import json

numbers = [2,3,4,5,7,10]

filename = 'number.json'
with open(filename,'w') as file:
    json.dump(numbers,file)

运行时出现了:AttributeError: module ‘json’ has no attribute ‘dump’
意为,json模块中并不包含dump属性
最后看了挺久才发现,模块的名字被我命名成了json.py,想要引入的模块也是json.py,两个文件名字发生冲突才出现了这个问题。
解决方式:
把自己的模块名称换成其他的名字即可。

猜你喜欢

转载自blog.csdn.net/liuxiaobao666/article/details/110873288