eval

3分钟让你明白JSON是什么

跟風遠走 提交于 2019-11-26 01:22:26
摘要 本文是从 Understanding JSON: the 3 minute lesson这篇文章翻译而来。看了这篇文章,你就知道为什么说国外的月亮是圆的了,思维方式不是一个数量级的,它完全把你整个脑海里面的思绪全部都理了出来,有种读意识流和散文的享受。 如果你跟我一样(我担心你就是),那么,到目前为止,这应该是你对JSON的经验: 两个月前你从没听说过JSON 一个月前你听说了这个词但没有留意 一周前你发现这个词被提到多次,开始想,没错…又有一些垃圾东西要学了 今天你被心灵深处的一个闹铃闹醒,心想:这该死的json究竟是个什么东西?为什么突然间到处都是它了! 于是晚上我乘坐了一辆慢腾腾的公交回到家(周五通常都是很慢),然后给自己找了一大堆关于JSON资料。所以我可以文雅的带你进入JSON的大门。 这几个字母是什么意思? JavaScript Object Notation. [一个滑稽的名字。它应该被称作Lightweight Ecmascript Object Notation,或简称’ LEON ’。 ] 它是个什么东西? JSON是一种传递对象的语法,对象可以是name/value对,数组和其他对象。 下面是一小段JSON代码: { "skillz": { "web": [ { "name": "html", "years": "5" }, { "name": "css

What does Python's eval() do?

。_饼干妹妹 提交于 2019-11-26 01:19:35
问题 In the book that I am reading on Python, it keeps using the code eval(input(\'blah\')) I read the documentation, and I understand it, but I still do not see how it changes the input() function. What does it do? Can someone explain? 回答1: The eval function lets a Python program run Python code within itself. eval example (interactive shell): >>> x = 1 >>> eval('x + 1') 2 >>> eval('x') 1 回答2: eval() interprets a string as code. The reason why so many people have warned you about using this is

(1, eval)('this') vs eval('this') in JavaScript?

守給你的承諾、 提交于 2019-11-26 00:57:40
问题 I start to read JavaScript Patterns, some codes confused me. var global = (function () { return this || (1, eval)(\'this\'); }()); Here are my questions: Q1: (1, eval) === eval ? Why and how does it work? Q2: Why not just var global = (function () { return this || eval(\'this\'); }()); or var global = (function () { return this; }()); 回答1: The difference between (1,eval) and plain old eval is that the former is a value and the latter is an lvalue. It would be more obvious if it were some

Security of Python's eval() on untrusted strings?

大城市里の小女人 提交于 2019-11-26 00:25:50
问题 If I am evaluating a Python string using eval(), and have a class like: class Foo(object): a = 3 def bar(self, x): return x + a What are the security risks if I do not trust the string? In particular: Is eval(string, {\"f\": Foo()}, {}) unsafe? That is, can you reach os or sys or something unsafe from a Foo instance? Is eval(string, {}, {}) unsafe? That is, can I reach os or sys entirely from builtins like len and list? Is there a way to make builtins not present at all in the eval context?

Are eval() and new Function() the same thing?

五迷三道 提交于 2019-11-26 00:19:25
问题 Are these two functions doing the same thing behind the scenes? (in single statement functions) var evaluate = function(string) { return eval(\'(\' + string + \')\'); } var func = function(string) { return (new Function( \'return (\' + string + \')\' )()); } console.log(evaluate(\'2 + 1\')); console.log(func(\'2 + 1\')); 回答1: No, they are not the same. eval() evaluates a string as a JavaScript expression within the current execution scope and can access local variables. new Function() parses

How to mathematically evaluate a string like “2-1” to produce “1”?

柔情痞子 提交于 2019-11-26 00:15:53
问题 I was just wondering if PHP has a function that can take a string like 2-1 and produce the arithmetic result of it? Or will I have to do this manually with explode() to get the values left and right of the arithmetic operator? 回答1: I know this question is old, but I came across it last night while searching for something that wasn't quite related, and every single answer here is bad. Not just bad, very bad. The examples I give here will be from a class that I created back in 2005 and spent

How to evaluate formula passed as string in PHP?

試著忘記壹切 提交于 2019-11-25 23:34:53
问题 Just trying to figure out the proper and safer way to execute mathematical operation passed as string. In my scenario it is values fetched from image EXIF data. After little research I found two way of doing it. first, using eval : function calculator1($str){ eval(\"\\$str = $str;\"); return $str; } second, using create_function : function calculator2($str){ $fn = create_function(\"\", \"return ({$str});\" ); return $fn(); }; Both examples require string cleanup to avoid malicious code

Dynamic Expression Evaluation in pandas using pd.eval()

五迷三道 提交于 2019-11-25 23:27:50
问题 Given two DataFrames np.random.seed(0) df1 = pd.DataFrame(np.random.choice(10, (5, 4)), columns=list(\'ABCD\')) df2 = pd.DataFrame(np.random.choice(10, (5, 4)), columns=list(\'ABCD\')) df1 A B C D 0 5 0 3 3 1 7 9 3 5 2 2 4 7 6 3 8 8 1 6 4 7 7 8 1 df2 A B C D 0 5 9 8 9 1 4 3 0 3 2 5 0 2 3 3 8 1 3 3 4 3 7 0 1 I would like to perform arithmetic on one or more columns using pd.eval . Specifically, I would like to port the following code: x = 5 df2[\'D\'] = df1[\'A\'] + (df1[\'B\'] * x) ...to code

Why exactly is eval evil?

僤鯓⒐⒋嵵緔 提交于 2019-11-25 23:25:12
问题 I know that Lisp and Scheme programmers usually say that eval should be avoided unless strictly necessary. I’ve seen the same recommendation for several programming languages, but I’ve not yet seen a list of clear arguments against the use of eval . Where can I find an account of the potential problems of using eval ? For example, I know the problems of GOTO in procedural programming (makes programs unreadable and hard to maintain, makes security problems hard to find, etc), but I’ve never

How can I evaluate a C# expression dynamically?

删除回忆录丶 提交于 2019-11-25 23:22:16
问题 I would like to do the equivalent of: object result = Eval(\"1 + 3\"); string now = Eval(\"System.DateTime.Now().ToString()\") as string Following Biri s link, I got this snippet (modified to remove obsolete method ICodeCompiler.CreateCompiler() : private object Eval(string sExpression) { CSharpCodeProvider c = new CSharpCodeProvider(); CompilerParameters cp = new CompilerParameters(); cp.ReferencedAssemblies.Add(\"system.dll\"); cp.CompilerOptions = \"/t:library\"; cp.GenerateInMemory = true