eval

What is the exact meaning of the find2perl perl shebang + eval?

穿精又带淫゛_ 提交于 2019-12-19 04:07:05
问题 What exacly do the following? #! /usr/bin/perl -w eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if 0; #$running_under_some_shell the if 0 is never true, so the eval part will never executed, and the eval is strange too - what is the value of $0 in this context (inside single quotes?) Ps: taken from the result of the find2perl command 回答1: Best guess - as in this comment #$running_under_some_shell , it's to detect if the script is being run by some shell other than perl, e.g. bash. the if 0 is

Why does this string not work with ast.literal_eval

≡放荡痞女 提交于 2019-12-19 03:31:42
问题 I get a malformed string error. Here is my testings >>> eval("'Hello:: '+'fdsfds'") 'Hello:: fdsfds' >>> import ast >>> ast.literal_eval("'Hello:: '+'fdsfds'") Traceback (most recent call last): File "<pyshell#4>", line 1, in <module> ast.literal_eval("'Hello:: '+'fdsfds'") File "C:\Python27\lib\ast.py", line 80, in literal_eval return _convert(node_or_string) File "C:\Python27\lib\ast.py", line 79, in _convert raise ValueError('malformed string') ValueError: malformed string 回答1: From the

JS中如何将JSON的字符串解析成JSON数据格式

谁说我不能喝 提交于 2019-12-19 01:45:32
1.使用eval()函数 服务器端返回json形式的字符串 js中使用eval()解析成js对象 为什么这里要写("(+data+)"),因为eval本身的问题。 由于json是以”{}”的方式来开始以及结束的,在JS中,它会被当成一个语句块来处理,所以必须强制性的将它转换成一种表达式。 加上圆括号的目的是迫使eval函数在处理JavaScript代码的时候强制将括号内的表达式(expression)转化为对象,而不是作为语句(statement)来执行。举一个例子,例如对象字面量{}, 如若不加外层的括号,那么eval会将大括号识别为JavaScript代码块的开始和结束标记,那么{}将会被认为是执行了一句空语句。 2.使用function()对象来进行返回解析 来源: https://www.cnblogs.com/freezy/p/7010526.html

Why must “exec” (and not “eval”) be used for Python import statements?

自作多情 提交于 2019-12-18 12:23:25
问题 I'm trying to run a snippet of Python from within Java, using Jython. If I use an exec statement to import, everything works. PythonInterpreter pi = new PythonInterpreter(); pi.exec("import re"); PythonObject o = pi.eval("re.match('abc', 'abc123')"); // returns a MatchObject o = pi.eval("re.match('abc', 'def123')"); // returns Py.None If, however, I try to combine the two lines, all hell breaks loose. This: PythonInterpreter pi = new PythonInterpreter(); pi.eval("import re"); // exception!

Escaping single quotes in JavaScript string for JavaScript evaluation

天大地大妈咪最大 提交于 2019-12-18 11:00:48
问题 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 =

Python Class dynamic attribute access

眉间皱痕 提交于 2019-12-18 09:29:20
问题 I want to access a class attribute by a string with its name. Something like: class a: b=[] c='b' eval('a.'+c+'=1') But that doesn't work in Python. How can I do this? 回答1: Use setattr: In [1]: class a: ...: b = [] ...: In [2]: setattr(a, 'b', 1) In [3]: a.b Out[3]: 1 Use getattr for the reverse: In [4]: getattr(a, 'b') Out[4]: 1 In [5]: getattr(a, 'x', 'default') Out[5]: 'default' I very much suspect, though, that there is a better way to achieve whatever your goal is. Have you tried using a

Alternatives to eval() for multiple nested objects

南笙酒味 提交于 2019-12-18 08:48:18
问题 I'm trying to create a generic i18n solution for a HTML app I'm working in. I'm looking for alternatives to use eval() to call deeply nested Javascript objects: Suppose the following HTML example: <div id="page1"> <h1 data-i18n="html.pageOne.pageTitle"></h1> </div> and it's companion Javascript (using jQuery): var i18n; i18n = { html: { pageOne: { pageTitle: 'Lorem Ipsum!' } } }; $(document).ready(function () { $('[data-18n]').each(function () { var q; q = eval('i18n.' + $(this).attr('data

Using eval() to set global variables

允我心安 提交于 2019-12-18 08:26:13
问题 My code to set a global variable using eval is not working. It's as if the assignment is not called at all, but no script errors occur. <script type="text/javascript"> $(function() { setTimeout(function() { eval('var x = 1;'); alert(x); }, 0); }); </script> <div onclick="alert(x);">Click to see 'x'</div> When the page loads, the alert shows what I expect; it confirms that x = 1. But after that, I click on the div and get a javascript error that x is undefined. How do I make eval add this

Eval alternative

。_饼干妹妹 提交于 2019-12-18 07:16:10
问题 This code works as a calculator, but the scratch pad at codeacademy tells me that eval is evil. Is there another way to do the same thing without using eval? var calculate = prompt("Enter problem"); alert(eval(calculate)); 回答1: eval evaluates the string input as JavaScript and coincidentally JavaScript supports calculations and understands 1+1 , which makes it suitable as a calculator. If you don't want to use eval , which is good, you have to parse that string yourself and, finally, do the

PHP variable value from string

心不动则不痛 提交于 2019-12-18 07:07:10
问题 How can I get value from variable which is string ? $Member_Student = 3600; $selectedItem = "Member_Student"; $price = "$" . $selectedItem; print_r($price); //prints $Member_Student instead of 3600 I cannot use eval function. 回答1: Use curly braces to denote a variable: $Member_Student = 3600; $selectedItem = "Member_Student"; $price = ${$selectedItem}; print_r($price); // prints 3600 回答2: use 2 $ signs: var_dump($$selectedItem) 回答3: To get a variable from another variable containing its name