我在Python 3的開發,我有我的階級色彩的參數的方法,但是當 我嘗試使用方法:如何在Python中修復錯誤類型的對象?
def __init__(self, name, color=Color.Color("none"), style="solid", width="1px"):
self.__name = name
self.__style = style
self.__width = width
if color.get_name() == "none":
color.color_by_name('Black')
這是錯誤:
File ................, line 10, in __init__
if color.get_name() == "none":
AttributeError: 'str' object has no attribute 'get_name'
似乎'Color.Color()'不是一個類,而是一個返回字符串的方法。我對嗎? – aIKid
你可以請你出示你的Color類嗎? – aIKid
追溯的其餘部分是什麼?出於某種原因,'color'是一個字符串。也許默認值是一個字符串,或者在某些特定情況下傳遞的參數是一個字符串。 – delnan