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

751 views python
10

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.

answered question

Welcome to StackOverflow! Please read about how to ask a question (particularly how to create a good example) in order to get good responses. In particular what is your expected output?

1 Answer

2

The executeCommand function in your program takes an input myDoc and prints the input.
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. This function prints hello and returns back to the calling program main which then terminates as there are no more statements.

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

posted this

Have an answer?

JD

Please login first before posting an answer.