eval

Escaping single quotes in JavaScript string for JavaScript evaluation

烂漫一生 提交于 2019-11-30 02:55:14
I have a project, in which some JavaScript var is evaluated. Because the string needs to be escaped (single quotes only), I have written the exact same code in a test function. I have the following bit of pretty simple JavaScript code: function testEscape() { var strResult = ""; var strInputString = "fsdsd'4565sd"; // Here, the string needs to be escaped for single quotes for the eval // to work as is. The following does NOT work! Help! strInputString.replace(/'/g, "''"); var strTest = "strResult = '" + strInputString + "';"; eval(strTest); alert(strResult); } And I want to alert it, saying:

python 中的eval与exec

老子叫甜甜 提交于 2019-11-30 02:44:41
eval类似exec,是使用python编译器运行表达式和语句 两者区别在于:eval是编译表达式并返回值(如: eval("'hello'*2") 结果是 hellohello) exec则是运行一部分代码,并且不像eval那样返回结果,exec的返回值永远是None,且exec可运行多行代码(如: exec("l=[1,2,3]\nfor i in l:\nprint(i,end=',')") 输出为"1,2,3," 并且没有返回值) eval 可以把字符串里的字符转换为可执行代码,但只支持一行字符。可以返回执行后得到的值 exec 可以把字符串里的字符转换为可执行代码,可以支持多行字符。但是拿不到返回结果 来源: https://www.cnblogs.com/yanhuaqiang/p/11547364.html

Bash nested quotes and eval

拈花ヽ惹草 提交于 2019-11-30 01:47:47
问题 I'm having difficulty nested quotes within a bash script argv="su -c '$RVM_PATH wrapper $config_rvm \'$PASSENGER_RVM_BIN $command $options\'' web" eval $argv The above got me eval: line 162: unexpected EOF while looking for matching `'' eval: line 163: syntax error: unexpected end of file 回答1: argv="su -c \"$RVM_PATH wrapper $config_rvm \\\"$PASSENGER_RVM_BIN $command $options\\\"\" web" 回答2: That's because \' doesn't have any special meaning within a single-quoted string; it means simply

Convert string to executable code at run time in c#?

ぃ、小莉子 提交于 2019-11-29 23:33:12
问题 Is there any way I can convert a string of code into executable code at runtime in c#? So if I have a file of predicates This is normal text in a txt file u => u.Contains("android") && u.Contains("webkit") u => u.Contains("iphone") && u.Contains("webkit") I would want to read it in via my program and then capture each predicate as a string and then convert it to code on the fly. Something like: string[] predicates = ///get file contentsa foreach(var predicate in predicates) { if(userAgent

js的json序列化和反序列化

孤街醉人 提交于 2019-11-29 23:23:41
(1)序列化   即js中的Object转化为字符串 1.使用toJSONString var last=obj.toJSONString(); //将JSON对象转化为JSON字符 2.使用stringify var last=JSON.stringify(obj); //将JSON对象转化为JSON字符 (2)反序列化 即js中JSON字符串转化为Object 1.使用parse var obj = JSON.parse(data); //由JSON字符串转换为JSON对象 2.使用parseJSON var obj = data.parseJSON(); //由JSON字符串转换为JSON对象 3.使用eval var obj=eval("("+data+")"); 为什么要 eval这里要添加 "("+data+");//”呢? 原因在于:eval本身的问题。 由于json是以”{}”的方式来开始以及结束的,在JS中,它会被当成一个语句块来处理,所以必须强制性的将它转换成一种表达式。 来源: https://www.cnblogs.com/yangyangming/p/11538443.html

How safe is SymPy's sympify(<string>).evalf()?

随声附和 提交于 2019-11-29 19:56:50
问题 We know Python's eval() is evil http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html and threads throughout StackOverflow suggest to use SymPy's evalf() . As a Python newbie, I can't really convince myself that evalf() is safe as I lack the skills. Can anyone elaborate on what evalf() does (different)? 回答1: There is nothing common between python eval and sympy evalf (the latter is for calculating the numeric value of sympy expression trees and it has nothing to do with parsing,

ImplementIon of eval() in Java [duplicate]

孤街醉人 提交于 2019-11-29 18:17:37
This question already has an answer here: Is there an eval() function in Java? 11 answers My question has to do with the phenomenon of non existence of function eval() in Java. After a bit of reading on the Internet I found out that the best thing I could do is to create my own parser as a Java function. But how to do that? What I need actually is a function that reads the first column of the above array and returns one after another all these values. Note however that these values are Strings are stored in a String array, thus are Strings, however they represent objects of different types,

Unexpected $end in eval()'d code

空扰寡人 提交于 2019-11-29 18:17:33
问题 I hate to ask such a specific question, but I'm getting an error I can't figure out. This is in a cron job which runs on the hour. I'm creating an array of tasks, each of which has a date check which is supposed to be eval()'d. $todo = array(); $todo[] = array( "date('z')%3 == 0", "Task 1" ); $todo[] = array( "date('N') == 1", "Task 2" ); foreach( $todo as $task ) { if( eval($task[0]) ) { echo $task[1]; } } For some reason the eval() line is giving me this error. Note that I am getting this

Why is `$@` untrustworthy?

为君一笑 提交于 2019-11-29 17:38:21
问题 I seem to recall that it is not safe to trust the value of $@ after an eval . Something about a signal handler having a chance to set $@ before you see it or something. I am also too tired and lazy right now to track down the real reason. So, why is it not safe to trust $@ ? 回答1: The Try::Tiny perldoc has the definitive discussion of the trouble with $@ : There are a number of issues with eval. Clobbering $@ When you run an eval block and it succeeds, $@ will be cleared, potentially

Tensorflow Estimator源码分析

淺唱寂寞╮ 提交于 2019-11-29 17:26:48
Estimator是Tensorflow的高阶API。除了Tensorflow官方定义的内置Estimator之外,用户也可以实现自定义的Estimator。 Estimator定义 Estimator的构造如下: def __init__(self, model_fn, # 定义模型,根据不同的模式分别定义训练、评估和预测的图。 model_dir=None, # 模型导出目录 config=None, # 配置参数 params=None, # 自定义Estimator的额外参数 warm_start_from=None): # 模型热启动 其中最核心的参数为 model_fn ,其接口如下 def _model_fn(features, # 特征,可以是Tensor或dict of Tensor labels, # 标签 mode, # 模式 params, # 自定义参数,即上面Estimator构造函数中的params config): # 配置参数 model_fn 会被Estimator多次调用,通过调用Tensorflow的layer来实现模型。通过模式字段(ModeKeys.TRAIN, ModeKeys.EVAL, ModeKeys.PREDICT)来判断是训练、评估还是预测阶段,分别构造不同的图。 model_fn 的返回结构为 EstimatorSpec