简体   繁体   English

如何将输入作为参数传递给python中的另一个函数? 不是

[英]How do you pass input as parameter to another function in python? It doesn't

def executeCommand(myDoc): 
    print(myDoc)
    return 

def insert():
    print("insert command:")
    return

def delete():
    print("delete command:")
    return

def main():
    print("Functional Text Editor ")
    executeCommand(input("Type in file name: "))

if __name__ == '__main__':
    main()

The main runs then prompts the "Type in file name:" but does nothing after that. 主运行然后提示“键入文件名:”,但此后不执行任何操作。

The executeCommand function in your program takes an input myDoc and prints the input. 程序中的executeCommand函数接受输入myDoc并打印输入。
When the program is run, it does precisely that. 当程序运行时,它正是这样做的。 The input hello in the given example below is taken as an input to the function executeCommand. 以下给定示例中的输入hello用作函数executeCommand的输入。 This function prints hello and returns back to the calling program main which then terminates as there are no more statements. 该函数打印hello并返回到调用程序主程序,然后由于没有更多语句而终止。

>>> def executeCommand(myDoc): 
...     print(myDoc)
...     return 
... 
>>> def insert():
...     print("insert command:")
...     return
... 
>>> def delete():
...     print("delete command:")
...     return
... 
>>> def main():
...     print("Functional Text Editor ")
...     executeCommand(input("Type in file name: "))
... 
>>> if __name__ == '__main__':
...     main()
... 
Functional Text Editor 
Type in file name: hello
hello
>>> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将命名参数传递给另一个函数需要的函数? - How do you pass a named parameter into a function that another function needs? 如何将mean()作为输入参数传递给Python中的另一个函数? - How to pass mean() as input parameter to another function in Python? 如何将参数列表传递给Python中的另一个函数? - How to pass a parameter list to another function in Python? 如何在另一个函数中将Python pandas函数作为变量/参数传递? - How to pass a Python pandas function as a variable/parameter in another function? 如何将带有参数的 function 作为参数传递给 Python 中的另一个 function? - How pass a function with parameters as a parameter to another function in Python? 如何在函数中将用户输入作为参数传递? - How do I pass user input as a parameter in a function? 将函数参数作为参数传递给python中的另一个函数 - pass a function parameter as an argument to another function in python 如何将参数从一个函数传递给另一个函数? - How do you pass arguments from one function to another? 如何在Python中传递接收参数作为另一个函数的参数的方法 - How to pass a method that receives parameters as a parameter of another function in Python 如何将新的字典名称作为参数传递给Python中的函数? - How do I pass a new dictionary name as a parameter to a function in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM