I wanted to let the user enter a python command, and then wanted to display the function of the command, so i used:
x = input("Enter the python command: ") print(x.__doc__)
But every time i run it i get only one output and that is it gives string function. Can anybody suggest a better alternative so that the output is not based on string?
when i fill myself the output is just what i wanted,
print(abs.__doc__)
the above given code gives the function of abs, what i wanted but if i entered abs() that got stored in x, then it’s not able to give desired output,as it is taken as some string. I need to know how can i use a user entered command and give it’s syntax and description in output.
Advertisement
Answer
input() will return a string so no matter what the user enters it will always show you the string
documentation.
you can use x=eval(input())
but use it with caution