![](/img/trans.png)
[英]Python - AttributeError: type object 'MyClass' has no attribute 'name'
[英]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.