Note that there are some explanatory texts on larger screens.

plurals
  1. POPython - Evaluating a string expression in a string
    primarykey
    data
    text
    <p>I am trying to do something like this </p> <p><a href="https://stackoverflow.com/questions/2371436/evaluating-a-mathematical-expression-in-a-string">Evaluating a mathematical expression in a string</a> </p> <p><strong>Update - Some details about the app</strong></p> <p>The app 'exposes' some variables to the users. An example of an exposed variable is user_name. The user of the app can then create a new variable called 'user_name_upper' that can be set as user_name.upper(). Another example is exposed variables first_name and last_name and the user can create a new variable called 'full_name = last_name.upper() + ',' + first_name.upper()'. This is entered using a input box UI element. So no hooks into the program. Or think of this as a report like excel where I can create a new column to be a manipulation of some already defined variables.</p> <p>The users of this app are not programmers. But they can be given a list of examples to find their way around string manipulations</p> <p>However, my expression will be used for string manupulation. Something like "string3 = string1 + string2". Here I'd like set the value of string3 to the value of string1 appended with string2. Or "string1 = string2.lower()"</p> <p>I have researched and have come to the conclusion that eval can be used but is very dangerous. From what I understand, ast_literal_eval() will not work with string manipulation methods like lower() as described here <a href="https://stackoverflow.com/questions/12080197/why-does-this-string-not-work-with-ast-literal-eval">Why does this string not work with ast.literal_eval</a> </p> <p>Any suggestion on how to go about this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload