eval

Doing math in vb.net like Eval in javascript

十年热恋 提交于 2019-11-26 08:31:38
问题 Is there any way to parse a string in vb.net (like, built in methods), that can do math like Eval can? For example, 3+(7/3.5) as a string would return 2. I am not asking for you to code this for me, I just want to know if there is a built in way to do this, if there is not I will code it myself. I can wager that it would not be able to parse stuff like Sin(90) on its own, and I understand that would need to be replaced by Math.Sin(90). If there is a built in method, how do you use it? 回答1:

Is Javascript eval() so dangerous? [duplicate]

陌路散爱 提交于 2019-11-26 07:44:48
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: When is JavaScript’s eval() not evil? I am writing a script in which users have to write in a currency amount, some examples could be (user input >> converts to), with USD as default currency: 50 >> 50.0 USD 50.5 >> 50.5 USD 50+1 USD >> 51.0 USD 50 GBP >> 50.0 GBP I want to make this as smooth as possible, therefore I want to use JavaScript (it\'s a web app based on PHP/MySql + JavaScript). I want to use regex

Are there any way to execute a query inside the string value (like eval) in PostgreSQL?

本小妞迷上赌 提交于 2019-11-26 07:42:30
问题 I want to do like this: SELECT (EVAL \'SELECT 1\') + 1; Are there any way to do like this ( EVAL ) in PostgreSQL? 回答1: If the statements you are trying to "eval" always return the same data type, you could write an eval() function that uses the EXECUTE mentioned by Grzegorz. create or replace function eval(expression text) returns integer as $body$ declare result integer; begin execute expression into result; return result; end; $body$ language plpgsql Then you could do something like SELECT

Eval is evil… So what should I use instead?

不羁岁月 提交于 2019-11-26 07:35:55
问题 An ajax request returns me a standard JSON array filled with my user\'s inputs. The input has been sanitized, and using the eval() function, I can easily create my javascript object and update my page... So here\'s the problem. No matter how hard I try to sanitize the inputs, I\'d rather not use the eval() function. I\'ve checked google for ways to use \"JSON in AJAX without eval\" and have ran accross a bunch of different methods... Which one should I use? Is there a standard, proven-secure

Python: How can I run eval() in the local scope of a function

雨燕双飞 提交于 2019-11-26 06:49:34
问题 I try to use eval() in a local scope of a function. However it always evaluate in the global scope. Self contained examples: 1- This code works: var1 = 1 var2 = 2 var3 = 3 myDict = dict((name, eval(name)) for name in [\"var1\", \"var2\", \"var3\"]) print(myDict[\"var1\"]) 2- Throws NameError for lvar1 def test1(): lvar1 = 1 lvar2 = 2 lvar3 = 3 myDict = dict((name, eval(name)) for name in [\"lvar1\", \"lvar2\", \"lvar3\"]) print(myDict[\"lvar1\"]) 3- Same outcome as 2. def test2(): lvar1 = 1

Execute PHP code in a string [duplicate]

女生的网名这么多〃 提交于 2019-11-26 06:47:52
问题 This question already has an answer here: PHP eval issue with PHP + HTML code 5 answers I have my page contents saved in a database and would like to execute any php code in the string. So if my string was: <h1>Welcome</h1><?php echo $motto?><br/> I only want to execute echo $motto . Using eval() will try to execute <h1>Welcome</h1> . Any way to do this? 回答1: Needless to say you should find another solution ASAP. In the meantime you can eval the code like this: $str = '<h1>Welcome</h1><?php

Restricting eval() to a narrow scope

白昼怎懂夜的黑 提交于 2019-11-26 06:37:59
问题 I have a javascript file that reads another file which may contain javascript fragments that need to be eval()-ed. The script fragments are supposed to conform to a strict subset of javascript that limits what they can do and which variables they can change, but I want to know if there is some way to enforce this by preventing the eval from seeing variables in the global scope. Something like the following: function safeEval( fragment ) { var localVariable = g_Variable; { // do magic scoping

Why {} + {} is NaN only on the client side? Why not in Node.js?

怎甘沉沦 提交于 2019-11-26 06:15:50
问题 While [] + [] is an empty string, [] + {} is \"[object Object]\" , and {} + [] is 0 . Why is {} + {} NaN? > {} + {} NaN My question isn\'t why ({} + {}).toString() is \"[object Object][object Object]\" while NaN.toString() is \"NaN\" , this part has an answer here already. My question is why does this happen only on the client side? On the server side (Node.js) {} + {} is \"[object Object][object Object]\" . > {} + {} \'[object Object][object Object]\' Summarizing : On the client side: [] + [

AttributeError: &#39;PandasExprVisitor&#39; object has no attribute &#39;visit_Ellipsis&#39;, using pandas eval

怎甘沉沦 提交于 2019-11-26 06:08:53
问题 I have a series of the form: s 0 [133, 115, 3, 1] 1 [114, 115, 2, 3] 2 [51, 59, 1, 1] dtype: object Note that its elements are strings : s[0] \'[133, 115, 3, 1]\' I\'m trying to use pd.eval to parse this string into a column of lists. This works for this sample data. pd.eval(s) array([[133, 115, 3, 1], [114, 115, 2, 3], [51, 59, 1, 1]], dtype=object) However, on much larger data (order of 10K), this fails miserably! len(s) 300000 pd.eval(s) AttributeError: \'PandasExprVisitor\' object has no

Use of eval in Python?

梦想的初衷 提交于 2019-11-26 03:38:37
问题 There is an eval() function in Python I stumbled upon while playing around. I cannot think of a case when this function is needed, except maybe as syntactic sugar. Can anyone give an example? 回答1: eval and exec are handy quick-and-dirty way to get some source code dynamically, maybe munge it a bit, and then execute it -- but they're hardly ever the best way, especially in production code as opposed to "quick-and-dirty" prototypes &c. For example, if I had to deal with such dynamic Python