AttributeError: 'Function' object has no attribute. Can't call on another function's attribute

AttributeError: 'Function' object has no attribute. Can't call on another function's attribute

"order_total" 在 (take_customer_order) 中创建的函数中工作正常,但由于某种原因我无法在我创建的新函数中调用它。

    def take_customer_order():
    new_pizza = input("Order a pizza?  (Y/N) ")
    if new_pizza.upper() == "N":
        return print("Have a nice day.")
    if new_pizza.upper() != "Y" and new_pizza.upper() != "N":
        return print("I'll take that as a no.  Have a nice day.")
    size, meats, veg, quantity = get_pizza_info(size=0, meats=0, veg=0, quantity=0)
    if size == 1:
        size_cost = 6.50
    if size == 2:
        size_cost = 9.50
    if size == 3:
        size_cost = 11.50
    meats_cost = (meats - 1) * 3.50
    veg_cost = (veg - 1) * 1.50
    order_total = 0
    pizza_total = (size_cost + meats_cost + veg_cost * quantity)
    print("Pizza total: $", "{:,.2f}".format(pizza_total))
    order_total += pizza_total
    while new_pizza != "N":
        new_pizza = input("Order a pizza?  (Y/N) ")
        if new_pizza.upper() == "N":
            break
        get_pizza_info(size, meats, veg, quantity)
        print("Pizza total: $", "{:,.2f}".format(pizza_total))
        order_total += pizza_total
    print("Your total is $", "{:,.2f}".format(order_total))
    return order_total, pizza_total

我在此处添加了一个新函数,希望能使 order_total 全局化:

def make_order_total_global():
    take_customer_order.order_total()
    return take_customer_order.order_total()

这是我提交的原始代码,调用 order_total.

时出现问题
def run_roccos_pizza_shop():
    revenue = 0
    patron_num = 0
    while True:
        partynum = input("Enter number in party or 'Close' to quit. ")
        if partynum.upper() == "CLOSE":
            print("Have a nice day!")
            break
        else:
            patron_num += int(partynum)
        revenue += take_customer_order.order_total()
    print("Customers served: ", patron_num)
    print("Total revenue $", "{:,.2f}".format(revenue))
    return patron_num, revenue

就是这样。显然,因为我的编辑主要是代码,所以我现在需要更多细节。 Deets deeeties deeetily doooooo

看起来 take_customer_order 需要 return 一些东西...函数没有您可以在其范围之外访问的属性。

您不能调用“take_customer_order.order_total()”函数,因为它在“take_customer_order()”函数中具有局部可见性,应该具有全局可见性才能被调用。我建议解包成两个不同的函数,以便使“take_customer_order.order_total ()”函数具有全局可见性。

例如。 来自:

def hi ():
    def hello ():
        print ("hello")
    hello ()

to:
def hello ():
    print ("hello")

def hi ():
    hello ()

更新:

试试这个:

def make_order_total_global():
    return take_customer_order()[0]