PYTHON:AttributeError:|PYTHON:AttributeError: ‘module’ object has no attribute’xxx’解决方法

初学python时在测试一个模块功能,经常出现代码没有问题但是运行报类似上面的错误,后面发现是文件名与import的模块名相同导致。
如下图:

PYTHON:AttributeError:|PYTHON:AttributeError: ‘module’ object has no attribute’xxx’解决方法
文章图片
报错
文件名与导入的模块重名了:

PYTHON:AttributeError:|PYTHON:AttributeError: ‘module’ object has no attribute’xxx’解决方法
文章图片
文件名 问题解决方法:
1. 命名py脚本时,不要与python预留字,模块名等相同。
【PYTHON:AttributeError:|PYTHON:AttributeError: ‘module’ object has no attribute’xxx’解决方法】2. 重命名后记得删除同目录下的的.pyc文件。

    推荐阅读