Hi all,

This is not a post about simply recvering user input with raw_input() and then using eval(), nor for input() use .

I remember having used this once, but can't get a hold of the old code so I turn to you for fresh ideas.

I am planning to create an application which would give access to the used to the actual functions in the imported modules. The user could really use the call to function_x(par1,par2...) on the input line ...

I believe (I may remember wrong and want too much though) that there was a module in Python allowing direct interpretation of the user input as Python code, related to the running app and imported modules in main.

Does any of you have any ideas about this? I think I'm not googling my needs the right way so I keep getting input() and raw_input() related issues.

Thanks in advance,

T-

Generally the eval() function will do ...

def add(x, y):
    return x + y

input_str = raw_input("Enter   add(4,3)  ")

print eval(input_str)

"""result for entering add(4,3) -->
7
"""

... however, employ some checking so a nasty user does not wipe out your drive with an improper input.

HI,

thanks for your answer, but unfortunately it isn't the answer, that's why I mentioned it wasn't for simple expression eval


Imagine that I could actually call my_class.my_func at input, not a simple math expression. What input capture function in what module would actually let me call the python functions directly?

I don;t know how to make myself clearer, it's practically the bahvior of the python shell itself, where you can import modules belonging to python and call any function inside. I would have to have a sort of shell for my own define python modules and function calls.

Is this possible?

This article has been dead for over six months. Start a new discussion instead.