繁体   English   中英

Python错误:AttributeError:类型对象'MyClass'没有属性'channel'

[英]Python error: AttributeError: type object 'MyClass' has no attribute 'channel'

我的代码需要帮助。 输入import test时,我self.channel在player.py中获取self.channel的列表,但遇到错误:AttributeError:当我尝试运行脚本时,类型对象'MyClass'没有属性'channel' 。

错误在此行中突出显示:

self.channel = test.MyClass.channel()

在test.py中显示:

from player import MyPlayer

class MyClass(xbmcgui.WindowXML):

def __init__(self, *args, **kwargs):
    self.channel = list()

在player.py中:

import test

class MyPlayer(xbmcgui.WindowXML):
  def __init__(self, *args, **kwargs):
      self.channel = test.MyClass.channel()

我想从test.py获取self.channel以获取字符串列表。 您能告诉我如何获取self.channel以从test.py脚本获取列表吗?

channel()删除括号。 它是一个字段,而不是一个函数。 将括号添加到MyClass以便调用构造函数。

self.channel = test.MyClass().channel

所有代码放在一起:

test.py

class MyClass:
    def __init__(self, *args, **kwargs):
        self.channel = list()

玩家

import test

class MyPlayer:
    def __init__(self, *args, **kwargs):
        self.channel = test.MyClass().channel

    def test(self):
        return self.channel


print MyPlayer().test()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM