使用Python从另一个函数中调用函数
问题描述:
我有一个任务可以根据用户输入从另一个函数调用函数。请参阅下面的代码片段以更好地了解我的要求。使用Python从另一个函数中调用函数
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 !!
如上所述,我如何实现类似的功能? 每次操作(创建/删除)后,我都想每次调用选择函数。
请帮我这里。提前致谢。
答
这是相当基本的,一个简单的初学者的Python教程将立即为您解答。
无论如何,我们来看一看:
def some_func(argument):
print('some_func called with ', argument)
def other_func():
argument = input()
some_func(argument)
other_func()
函数是对象,所以你可以,只要他们在各自的命名空间中调用它们。
尝试阅读关于如何调用函数的最基本的Python教程。 – DeepSpace