类型错误: 尝试调用方法时'tuple'对象不可调用



这是我目前的情况:

# -*- coding: cp1252 -*-
import time
class Item():
    def __init__(self, name, description, base_value):
        self.name = name
        self.description = description
        self.ingredients = ingredients
        self.base_value = value
    def __str__(self):
        return format(self.name, self.description, self.ingredients, self.base_value)

class Metal(Item):
    def __init__(self, name, description, ingredients, base_value):
        self.smelt_time = smelt_time
        self.smelted = smelted
    def __str__(self):
        return format(self.name, self.description, self.ingredients, self.base_value, self.smelt_time, self.smelted)
class Bronze_Ingot(Metal):
    def __init__(self):
        self.name = "Bronze Ingot",
        self.description = "A refined ingot of bronze."
        #self.ingredients = Tin_Ore(1)+Copper_Ore(1) <--- I will get these lines working later...
        self.base_value = 33
        self.smelt_time = 15
        self.smelted = ()            
class Fuel(Item):
    def __init__(self, name, description, ingredients, base_value):
        self.fuel_time = fuel_time
    def __str__(self):
        return format(self.name, self.description, self.ingredients, self.base_value, self.fuel_time)
class Cloth(Fuel):
    def __init__(self):
        self.name = "Cloth",
        self.description = "A piece of cotton cloth."
        #self.ingredients = 2 Cotton <--- I will get these lines working later... 
        self.base_value = 2
        self.fuel_time = 5

但是我对这个功能有很大的麻烦...

    def smelted(Fuel, Metal):
        if (Fuel.fuel_time - Metal.smelt_time) > 0:
            time.sleep(1)
            print "Smelting", Metal.name, "..."
            time.sleep(Metal.smelt_time)
            print "Time to forge!"

问题或多或少是让它工作。我和我的朋友在运行此功能时尝试了我们能想到的一切,但无济于事。以下是我们最近的尝试:

from Smelting_Progress import *
x = Cloth()
y = Bronze_Ingot()
y.smelted(x,y)

尝试运行此内容后,我收到此错误:

Traceback (most recent call last):
File "C:UsersWCS-HSSTUDENTDesktopFilesProject SAOfflineCodingNew Aincrad WorldItemsNAI_Smelted.pyw", line 6, in <module>
    Metal.smelted(Fuel, Metal)
TypeError: 'tuple' object is not callable

你有一个实例属性smelted;你在Metal.__init__()中设置它:

self.smelted = smelted

您的Bronze_Ingot子类将其设置为空元组:

self.smelted = ()            

不能让方法和元组使用相同的名称。重命名一个或另一个。

如果您打算将smelted()代码用作函数,请在顶层定义它(与类的缩进相同),并将其调用为函数,而不是方法:

smelted(x, y)

(注意,前面没有y.)。

最新更新