[英]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.