我正在尝试创建一个将两个函数作为参数并出现错误的函数。
我所做的是创建一个名为“ parent”的函数,该函数将2个函数作为参数(ux和ui)。但是ux也有参数,它从父函数获取参数:
import ID_Ui as Ui
ui = Ui.admin_panel()
# ui returns something like this :
'''Please choose one of the options below :
Please press 0 if you want to exit the program .
Please press 1 if you want to exit to main menu .
Please press 2 if you want exit to previous section .
Please press 3 if you want to create/modify user account .
Please press 4 if you want to create/modify company account .
Please press 5 if you want to create/modify document type .
Please press 6 if you want to create/modify document ID . '''
def child(*ui):
user_choice = ui
if user_choice == 3:
return 3
elif user_choice == 4:
return 4
elif user_choice == 5:
return 5
else:
return 'error'
def parent(ux, ui):
user_choice = ui
x = user_choice
if user_choice == 0:
return 0
elif user_choice == 1:
return 1
elif user_choice == 2:
return 2
else:
ux(x)
print(parent(child(), ui))
我希望当我输入[0:2]以外的数字时,它运行ux函数并将x变量作为参数传递给它。但是关于ux(x)行,我收到以下错误:
TypeError: 'int' object is not callable
答案 0 :(得分:0)
首先,我假设您正在调用的函数menu_conditions
实际上是parent
函数,但是我相信您应该对此进行修复。
第二,在最后一行上运行child()
时,它返回一个数字或字符串error
。如果您希望能够在child
文件夹中运行parent
,只需将其传递而不带括号,如下所示:
print(parent(child, ui))