Py学习  »  Python

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

Alex • 6 年前 • 1761 次点击  
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()

然后,主运行会提示“键入文件名:”但之后不执行任何操作。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/40979
文章 [ 1 ]  |  最新文章 6 年前
Anurag A S
Reply   •   1 楼
Anurag A S    7 年前

程序中的executecommand函数接受输入mydoc并打印输入。
当程序运行时,它正是这样做的。以下给定示例中的输入hello被视为函数executecommand的输入。此函数打印 hello 并返回到调用程序main,然后由于没有更多语句而终止。

>>> 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
>>>