eval

Using eval() to assess user input and some condition. What alternatives?

Using eval() to assess user input and some condition. What alternatives? Question: First, to provide some context, I am designing a console based version of Blackjack for entertainment and learning purposes. The code below was my solution to evaluate different conditions given user input. The function below handles sleep times and user inputs and its …

Total answers: 1

How to make menu using dict evaluation for small python guessing game

How to make menu using dict evaluation for small python guessing game Question: menu = { "1": "start_game()" "2": "player_stats()" "3": "high_scores()" "0": "exit_game()" } So let’s say if user inputs 1 in menu screen, I want to call start_game() function, I know there is other way to do this but just interested in this …

Total answers: 1

strange behaviour of locals() dictionaries when using eval

strange behaviour of locals() dictionaries when using eval Question: Please consider this code: from sklearn.model_selection import ParameterGrid def conf1(): return {"p1": [1,2], "p2": [4,5,6]} def f(aa, bb, cc): c = locals() print("CONFIG, locals():") for k, v, in c.items(): print(f"{k}: {v}") #> params = eval("conf1()") grid = ParameterGrid(params) #< d = {**c} print("CONF after eval") for …

Total answers: 1

Python: apply math order of operations to reorder strings following hierarchy in parentheses

Python: apply math order of operations to reorder strings following hierarchy in parentheses Question: How can be done with Python to reorder a string applying the math operations order with parenthesys? Let me use an example: "son(father(granpa)mother))" ===> "granpa father mother son" The idea is to reorder the original string using the standar math order …

Total answers: 3

Why do I get None in output in second line while using eval function?

Why do I get None in output in second line while using eval function? Question: I am executing this line of code – print(eval("print(2 +3)")) but this instead of giving output as 5 gives output- 5 None Asked By: TusharGaurav || Source Answers: When you try to get eval of something like eval("2") you are …

Total answers: 3

Calling round(), ceiling(), floor(), min(), max() in pandas eval

Calling round(), ceiling(), floor(), min(), max() in pandas eval Question: As title says, Is there a way to support round, ceiling, min, max, floor functions in pandas eval. DataFrame: import pandas as pd import numexpr as ne op_d = {‘ID’: [1, 2,3],’V’:[‘F’,’G’,’H’],’AAA’:[0,1,1],’E’:[102014,112019,122017] ,’D’:[‘2019/02/04′,’2019/02/01′,’2019/01/01′],’DD’:[‘2019-12-01′,’2016-05-31′,’2015-02-15′],’CurrentRate’:[7.5,2,2],’NoteRate’:[2,3,3],’BBB’:[0,00,4],’Q1′:[2,8,00],’Q2′:[3,5,7],’Q3′:[5,6,8]} df = pd.DataFrame(data=op_d) abs() and sqrt() function works with pandas eval. i.e. …

Total answers: 3