Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法

问题1:代码貌似没问题,运行时报错如下

e02c46afd9c845759c38d96a3ca2e6e1
Traceback (most recent call last):
File "/apps/svr/pyenv/versions/linkage/lib/python2.7/site-packages/linkage/op/boss_errorCheck/boss_errorCheck.py", line 353, in <module>
main()
File "/apps/svr/pyenv/versions/linkage/lib/python2.7/site-packages/linkage/op/boss_errorCheck/boss_errorCheck.py", line 347, in main
cust_bossagent(ext)
File "/apps/svr/pyenv/versions/linkage/lib/python2.7/site-packages/linkage/op/boss_errorCheck/boss_errorCheck.py", line 121, in cust_bossagent
custCreateCheck(BOSS_CUST_ID, resultext, cid)#客户注册eboss只同步没有异步反馈和归档
File "/apps/svr/pyenv/versions/linkage/lib/python2.7/site-packages/linkage/op/boss_errorCheck/boss_errorCheck.py", line 94, in custCreateCheck
bossagent = baseSQL.selectCustBossagent(BOSS_PRO_ORDER_CODE)
AttributeError: 'module' object has no attribute 'selectCustBossagent'

解决:①确实是代码有问题,程序应该是在baseSQL没有搜索到selectCustBossagent这个方法,把selectCustBossagent方法写进去baseSQL

②python代码在编译后会生成以pyc为文件名后綴的字节码文件,该字节码文件会经过python解释器来生成机器码文件来运行。当再次运行python文件时,解释器会直接调用该pyc的字节码文件运行直到py文件发生改变(解释器运行时会对比pyc的生成时间和py的修改时间)

问题解决方法:不要将python代码文件命名为python预留字,模块名等

 

posted @ 2021-01-15 11:27  fangxs666  阅读(879)  评论(0编辑  收藏  举报