关于python静态方法模块外访问报'module' object has no attribute

djvc 2016-06-04 03:45:26
common
| Log.py
| __init__.py
Exception
| ...
CmdOps
| SpecCmdOps.py
| __init__.py
——————————————————————————————————

Log.py 部分实现

class Log:

LOGER_NAME = "zyxd"
__instance = None

@staticmethod
def init(logconf):
logging.config.fileConfig(logconf);
Log.__instance = logging.getLogger(Log.LOGER_NAME)
Log.__instance.info(u"初始化成功")

@staticmethod
def i(msg):
if Log.__instance:
Log.__instance.info(msg)


Log.py所在__init__.py内容如下
from Log import Log

——————————————————————————————————

SpecCmdOps.py 所在目录__init__.py内容如下
from SpecCmdOps import SpecCmdOps

在SpecCmdOps.py
from ..Common import Log
class SpecCmdOps:
def somemethod(self):
Log.i(u"测试而已")


但是上面语句执行报错,'module' object has no attribute 'i'
在IDE里,是可以直接跳转到Log定义,打印Log内容如下
<module 'PyScript.Common.Log' from 'E:\my_work\PyScript\Common\Log.pyc'>

打印Log所有属性,的确没有看到相关i属性。

请大神指点迷津。。。。
...全文
636 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
fantasypan 2016-06-06
  • 打赏
  • 举报
回复
报错的Log指的是模块 你想要的Log是Log里面的类 应该是Log.Log.i("xxx")

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧