我有一个任务是根据用户输入从另一个函数调用函数。请参阅以下代码段以更好地了解我的要求。
def main():
Operation = raw_input(" \n Select the Operation \n\n 1. CREATE \n 2. DELETE \n Enter: \n")
Instance = raw_input(" \n Select the Instance \n\n 1. AsyncINT01 \n 2. AsyncOUT01 \n 3. Trans01 \n Enter: \n")
if (Operation == '1'):
Call create Function !!
if (Operation == '2'):
Call delete Function !!
def create():
if (Instance == '1'):
Create Somemthiing !!
if (Instance == '2'):
Create Somemthiing !!
def delete():
if (Instance == '1'):
Delete Somemthiing !!
if (Instance == '2'):
Delete Somemthiing !!
def choice():
Choice = raw_input(" \n Do you want to run the program again (yes/no) ? \n Enter: \n")
if (Choice == "yes"):
Call main Function !!
如上所述,我如何实现类似的功能? 在每次操作(创建/删除)之后,我想每次都调用选择函数。
请在这里帮助我。提前谢谢。
答案 0 :(得分:0)
这是相当基础的,一个关于python的简单入门教程将立即为您解答。
无论如何,看看:
def some_func(argument):
print('some_func called with ', argument)
def other_func():
argument = input()
some_func(argument)
other_func()
函数是对象,因此只要它们位于相应的命名空间中,就可以调用它们。