Questions tagged [eval]
eval is a function that allows a programmer to execute arbitrary code written in the same language, from a string variable within a code.
4,736
questions
0
votes
1
answer
25
views
Why does emacs lisp/elisp (contrary to Common Lisp) reject quoted symbol names as unknown variables?
The following function call works in Common Lisp, but fails with Emacs Lisp that does not accept the quoted symbol passed as the first argument, with the Debugger reporting a Lisp error: “void-...
0
votes
0
answers
23
views
Arguments from CSV as vector
I have a csv that contains my arguments for a function called eDMA.
One particular argument(vKeep)takes the following values, either 1 or a vector of n items c(1,2).
I have tried the following but it ...
-1
votes
0
answers
30
views
Evaluate an expression in ruby and get the variable value [duplicate]
After run
eval("a = 1")
I want to get
a = 1
But instead I just get 1:
irb(main):001:0> eval("a=1")
=> 1
irb(main):002:0> a
(irb):2:in `<main>': undefined local ...
1
vote
1
answer
25
views
Writing function using exec() instead of invoke() in R
I could use some help with a custom function that I've been working on that takes the parallel minima of a vector of variables (all date of diagnosis variables, with dx dates for cases and NA for ...
0
votes
1
answer
20
views
Using np.where inside of df.eval string in python
long time listener, first time caller..
I need to be able to call functions (custom made and otherwise, like numpy.where) as a string in a pandas dataframe eval statement. see example:
import pandas ...
-7
votes
0
answers
38
views
how to dump the environmental variable in lambda function? [closed]
[" File "/var/task/lambda-function.py", line 5, in lambda_handler\n 'result' : eval(event['input'])\n"," File "", line 1, in \n"]
Lambda_handler and lambda ...
0
votes
2
answers
31
views
JavaScript - execute eval in the caller's scope
eval() executes a string, and does it in the current scope. But what, if I need to make my own eval-like function, which will modify given string of code (not necessary synchronously), and then ...
0
votes
0
answers
9
views
Can I safely store Python function parameters in utf8 and then execute them with ast.literal_eval?
I want to store the output of a Python function's locals() in a persistent object in utf-8 so that a person can access human-readable parameters and also use them again, as in func(**ast.literal_eval(...
0
votes
0
answers
28
views
Django to eval(uate) a formula and calculate the result
In my Django model I have a field with a field, which captures a reference. Through templating, I replace {{val-x}} by the respective value. To identify bigger or smaller I use if(int(x<250))*500 e....
0
votes
1
answer
46
views
Calling a function as part of re.sub in Python "eval equivalent in perl"
I need to be able to call a function in a pattern matching statement with the matched patterned as argument and use the return result of the function as replacement for the matched pattern. In perl, ...
0
votes
0
answers
19
views
AttributeError: 'NoneType' object has no attribute 'n_feature'
I have trained a model with state dictionary and now i want to test a model on testing set. The problem is that it gives m_feature error when evaluating on testing set. I have no idea why i am getting ...
0
votes
1
answer
36
views
Why am I getting a TypeError: 'str' object is not callable when using eval() on string that is python code
I have the following code which manipulates a function in the form of string and adds a timer to while loops to see if they take 2 seconds without returning. If so it returns 'error, infinite loop.'
...
0
votes
0
answers
77
views
Using eval() while using json data
I am storing settings in json file > loading it > using eval to evaluate the stringified data.
However I am sure eval is not the best way to do it.
I would like to know if there is any better ...
2
votes
1
answer
27
views
Eval a function definition vs. variable function definition
If we define a function f() { ... } in eval(...), why isn't it available for the rest of the code, such as #button3's onclick?
As a comparison, if we define the function as f = () => { ... };, then ...
0
votes
1
answer
29
views
How to make menu using dict evaluation for small python guessing game
menu = {
"1": "start_game()"
"2": "player_stats()"
"3": "high_scores()"
"0": "exit_game()"
}
So let's say if user ...
0
votes
0
answers
37
views
python How to use eval with lambda
Is there a way that I can use eval with lambda?Because I tried to do it but I just got an error which was Traceback (most recent call last):
File "", line 1, in
NameError: name 'self' is ...
-1
votes
2
answers
38
views
JavaScript making a String into a variable name without eval
I wanted to get the value of an HTML input by using the dollar ($) sign, since I have to make a String the only way I can think of is using the eval() function, but since it is not recommended I ...
2
votes
1
answer
72
views
strange behaviour of the locals() dictionary when using eval
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(&...
2
votes
1
answer
48
views
Is there a way to use Optional.orElse in eval?
I have a function that returns Optional that I want to use in drools eval, e.g.
rule "some rule"
when
eval(func().orElse(1.0) > 0.0)
then
....
end
where func() has return ...
0
votes
0
answers
9
views
How to convert a string representation of a very large nested dictionary into a dictionary in python?
I have a very large string that is nested with dictionaries of lists of lists. The outermost dictionary is represented as a string:
largte_string = {{table: 0: [[[17907 10929] [{house1 17907} {node ...
0
votes
1
answer
17
views
call object method instead of global method in js new Function
i try make editor that allow user attach function to dynamic objects
each object have init method, allow user attach some actions on user input
think about this
user select baby and write in textarea
...
2
votes
2
answers
22
views
Load Cheerio/jQuery selectors, including methods as strings
I have a nodejs app, which uses cheerio for extracting parts of html from pages of multiple sites. The app runs through a JSON file and performs the scraping and extraction for each site, for all the ...
0
votes
1
answer
34
views
Error in eval(bysub, x, parent.frame()) : object 'Year' not found
I am trying to write a function using R data.table syntax. It has results if I just run this line countbyYr = data[, .(counts = uniqueN(Col_A)), by = .(Year)], but once I put it into a function (shown ...
1
vote
2
answers
89
views
Starting newly-inserted <script> after AJAX call and stopping removed <script> after another AJAX call
I'm doing a toy library in which the user can modify the DOM with AJAX, basically around:
fetch("/newpage").then(r => r.text()).then(html => {
var tmp = document.createElement('...
0
votes
0
answers
31
views
Run external javascript code dynamically as a part of the script
I need to execute some javascript code from a string as a part of the current script.
I tried to do it with eval, but for example there is a problem with classes declaration
let code = "class A { ...
0
votes
0
answers
41
views
How to handle formula with a variable name with % in it when using eval()?
I want to use python's eval() function to evaluate a formula, the formula is
formula = 'x% + y% + z'
the x% and y% are valid column name from a DataFrame, but when calling the eval(), it treat the % ...
2
votes
3
answers
43
views
Javascript eval() acting strange
I am creating my own kind of Message Boxes (normal OK dialogs and also Yes/No dialogs) that can popup on my website. When the user clicks "OK" or "Yes/No", callbacks are called ...
2
votes
2
answers
61
views
Creating an object from a chunk of R code without converting to a string
I am trying to turn an arbitrary chunk (not in the Rmarkdownsense) of code into an object that I can call to return either (1) the code's output or (2) the code and its output.
I can produce output (1)...
0
votes
0
answers
55
views
Why am I getting unexpected EOF while parsing in my eval() function
I am trying to make a "moderately scientific" calculator GUI using python's tkinter module.
I am fairly new to using classes and methods
I have run the code after "typing" in ...
0
votes
2
answers
35
views
Bash script eval with aws command producing "command not found"
I have a short bash script to take in an int from a user to identify to select a certain eks cluster.
When I use eval $(aws eks --region us-east-1 update-kubeconfig --name eventplatform$input)
I get ...
1
vote
1
answer
87
views
apply many expressions to one row of a matrix
I have input data X in the form of a single row of a matrix that is updated several times per second
# fake data
set.seed(123)
X <- matrix(rnorm(1),ncol = 10,nrow = 1)
I have a model in the form ...
1
vote
1
answer
99
views
SSH keys not considered while using "eval" in shell
I am trying to do a git clone in a shell script where the repo URL is evaluated dynamically.
I have tried below in my script:
git clone 'git_repo_url' works fine
x='git_repo_url'; git clone $x works ...
0
votes
1
answer
53
views
Python lambda and eval scoping within function
I have the following code
def foo(q, s):
a = 1
f = lambda x : eval(s)
return f(1)
foo(1, "x+a+q")
I would expect the function call to return 3, however I get a NameError ...
0
votes
1
answer
39
views
Bash Variable in Mongo eval command inserts empty data
I have a script that inserts data into Mongo from a CSV but I have to encrypt one of the columns before insertion.
#!/bin/bash
while IFS=, read -r f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12
do
...
2
votes
2
answers
79
views
malformed node or string on line 1 when I use ast.literal_eval using discord.py
I tried executing
import ast
ast.literal_eval('5+5')
Then I got ValueError: malformed node or string on line 1: <ast.BinOp object at 0x70e6bd2830>.
So then I tried another:
import ast
ast....
1
vote
1
answer
43
views
Is it safe to use eval for a client-side JavaScript calculator
I was making a calculator which is served as a static html page to the user's browser. The page is not designed to submit any information back to the server. Nothing else will be present on the web ...
0
votes
0
answers
17
views
Evaluating string with pandas column - variable is not defined error [duplicate]
Here is my code:
import pandas as pd
my_df = pd.DataFrame({'col1':[1], 'col2':[2]})
def simple_function(my_df = None):
for (index, row) in list(my_df.iterrows()):
print(row['col1'])
...
1
vote
1
answer
61
views
python string to a function call with arguments, without using eval
I have a string stored in a database stands for a class instance creation for example module1.CustomHandler(filename="abc.csv", mode="rb"), where CustomHandler is a class defined ...
3
votes
1
answer
47
views
Creating an alias for `git commit` accepting N arbitrary `-m` arguments
Using the Fish shell, I would like to create a function (gcom) to use as an alias for the git commit command, accepting an arbitrary number of string arguments and passing them as -m options, so that
...
0
votes
0
answers
35
views
How to prevent eval() from evaluating specific javascript keywords or statement?
I have an application where user can write JS code and save it in the back-end to perform some tasks later as they wish. But since eval() is very risky I want to prevent them to use only few keywords ...
0
votes
0
answers
48
views
Late code evaluation and also printing the code
I want to pass code to a test() routine, which has to :
print the code
execute it
and finally do stuff with the result.
should handle args in the background
For quick code snippets I can use eval(...
0
votes
0
answers
28
views
Python: How to pass a replacer function with parameters, to re.subn
I want to replace expressions between two markers, with the return value from eval'ing that expression, however, I want to pass the locals() context of where the re.subn is being called to the ...
0
votes
0
answers
16
views
How to run eval() function on codeblock generated from quill.js?
I am trying to let the user input the codeblock in a stylish way and save them to run later. For that purpose I found quill. But the code block generated by quill is text with bunch of HTML code used ...
0
votes
0
answers
39
views
How to evaluate a string expression for multiple arguments?
I have an api wrapper function that accepts custom arguments in addition to some defined parameters. For my use case this function needs to accept a variable size of custom arguments so I construct ...
-1
votes
1
answer
85
views
Python : Evaluate an expression without using eval() function
I'm looking forward to make a calculator to calculate an input such as 2*((25+2)/2)*(3**5) using python, without using eval function. is there any way?
0
votes
1
answer
48
views
How do I evaluate a variable from a string without using eval()? [duplicate]
Suppose I've got a set of background data measurements for different frequencies:
import numpy as np
C_bg_100kHz = 100*np.random.random(1000)
C_bg_200kHz = 200*np.random.random(1000)
Where ...
1
vote
1
answer
22
views
Simplify debugging output. Specific request for in-place command text replacement in BASH
OK, so, I have a debugging setup a little like this:
DVAR=();
function DBG() {
if [[ $1 == -s ]]; then shift; stackTrace; fi;
if [[ ! -z ${DVAR[@]} ]]; then
for _v in ${!DVAR[@]}; do
...
0
votes
1
answer
76
views
combination of eval + f-strings + match-case
How do I make the following work,
for i in ['int', 'bool']:
x = eval(f'match 1: \
case {i}(): print(1)')
that is I want to run a match-case f-string inside an eval.
0
votes
0
answers
24
views
pupetter with $eval with next()
Is puppeteer $eval is not working with jquery next() option?
await page.$eval(`a[href*=${listableItemsResponse.items[i].url}]`.next(), (el) => el.click());
produces TypeError: listableItemsResponse....
-1
votes
1
answer
63
views
NameError: name 'nan' is not defined in Series.apply(pd.eval)
When using eval to convert a list string to list type, it's ok to eval with nan in list
# Following two ways are both ok
#from numpy import nan
nan = float('nan')
lst = '[nan, 1]'
print(eval(lst))
...