eval

Eval/Exec with assigning variable - Python

佐手、 提交于 2019-12-31 05:14:11
问题 The below piece of code is aimed at converting a factorial into its products. E.g. "4!" --> "(4*3*2*1)" . This code does not work due to the line exec(codeToRun) . However, if I instead put the value of codeToRun in place of exec(codeToRun) then it works perfectly so why doesn't exec work? Doesn't work ↓ def checkSpecialChars(char, stringToCheck, codeToRun): while char in stringToCheck: currentString="" for i in range(len(stringToCheck)): if stringToCheck[i]==char: try: eval(codeToRun) except

Displaying milliseconds in TemplateField using Eval

左心房为你撑大大i 提交于 2019-12-31 04:15:08
问题 I have a template filed as listed below. I need to display millisecond part of DateTime also. I have read about the dateValue.ToString("fff") format in http://msdn.microsoft.com/en-us/library/bb882581.aspx How to: Display Milliseconds in Date and Time Values . What is the best way to display it in Template Field with Eval? CODE <asp:TemplateField HeaderText="Event Time"> <ItemTemplate> <asp:Literal ID="ltlTime" runat="server" Text='<%# Eval("LastChangeTime") %>' ></asp:Literal> <asp

Why is the eval class giving me a casting error from int to double?

牧云@^-^@ 提交于 2019-12-31 03:56:27
问题 I am trying to make a method that takes a string formula, and solves the integral of that formula by doing a Riemann's sum with very small intervals. I am using the ScriptEngine and ScriptEngineManager classes to evaluate the function (with the eval() method). For some reason, I am getting this error: Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double at sum.integral(sum.java:31) at sum.main(sum.java:13) import java.beans.Expression;

How to evaluate string that have exponential

ぃ、小莉子 提交于 2019-12-31 03:55:11
问题 Javax ScriptEngine and JEval works similarly, you input an string and send it to be evaluated, and it will return you the result of it: In ScriptEngine (almost the same in JEval): System.out.println(engine.eval("2*3+4")); will result in: 10.0 But when I try to make it an exponential: System.out.println(engine.eval("2^3+4")); will result in: 5.0 But it really should result in 12 (2^3 = 8, 8+4=12), so my question is how can I set it up in a way that the string which the will be all the whole

what are the issues javascript eval can pose

∥☆過路亽.° 提交于 2019-12-31 02:58:11
问题 i tried googling but didnt get a very specific answer.. then again, i might be not using the right keywords.. can someone point out the "security" issues javascript eval can cause? with examples with be very nice. will also do if you can point to an existing web resource which does the same. Edit : I only need the security implications for eval. 回答1: eval() may be a sign of poor design. For instance, sometimes people use it to access object properties because they don't know you can use the [

Why doesn't Perl's Try::Tiny's try/catch give me the same results as eval?

被刻印的时光 ゝ 提交于 2019-12-30 22:56:12
问题 Why doesn't the subroutine with try/catch give me the same results as the eval-version does? #!/usr/bin/env perl use warnings; use strict; use 5.012; use Try::Tiny; sub shell_command_1 { my $command = shift; my $timeout_alarm = shift; my @array; eval { local $SIG{ALRM} = sub { die "timeout '$command'\n" }; alarm $timeout_alarm; @array = qx( $command ); alarm 0; }; die $@ if $@ && $@ ne "timeout '$command'\n"; warn $@ if $@ && $@ eq "timeout '$command'\n"; return @array; } shell_command_1(

PHP eval(array_as_string) returns null

女生的网名这么多〃 提交于 2019-12-30 11:18:12
问题 $arr = eval("array('foo'=>'bar');"); // returns null var_dump($arr); Can someone please explain why did I get null instead of an array? 回答1: You need to return the array. From the docs: eval() returns NULL unless return is called in the evaluated code, in which case the value passed to return is returned. So you need to do: $arr = eval("return array('foo'=>'bar');"); 回答2: Did you mean eval("\$arr = array('foo'=>'bar');"); var_dump($arr); 回答3: The eval function executes the php code given to

ast.literal_eval for variables in python?

倖福魔咒の 提交于 2019-12-30 07:16:06
问题 Suppose I have a file example.py : import example VVV = 2 DictionaryNameB = { 'a' : VVV, 'bb' : 'SomethingB', 'c' : False, 'ccc' : None, 'dddd' : 'true', 'eeeee' : 0.123456, 'f' : 2, 'h' : [1,2,3] } I wrote a function that uses ast.literal_eval() : def getDicFromFile(self, dic_name): with open( 'example.py' ) as f: file_data = f.read() match = re.findall('%s[^{]+\{[^\}]+\}' % dic_name, file_data, re.MULTILINE)[0] # print(match) dicObject = ast.literal_eval(match[len(dic_name)+3:]) return

Bash function calling command given as argument

北战南征 提交于 2019-12-30 03:19:07
问题 How do you write a function in bash that executes the command that it is given as an argument, where The given command may be an alias Arguments must be passed on exactly as given; no evaluating may be done In other words, how to write an as-transparent-as-possible wrapper function. The goal of the wrapper function could for example be to set the current directory before and after the given command, and/or set environment variables, or time how long the given command takes,... As a simple

dynamic array names javascript

不羁的心 提交于 2019-12-29 07:50:07
问题 I have a few arrays with like names. ArrayTop[] ArrayLeft[] ArrayRight[] ArrayWidth[] I am trying to set the name dynamically in a function and then set value. I have tried many ways of dynamically picking the right array but have not come up with a solution. function setarray(a,b,c){ eval(Array+a+[b])=c } setarray('Top',5,100) In this example i am trying to set. ArrayTop[5]=100 回答1: If you are doing this in the browser, one possible solution would be to do: function setArray(a, b, c){ window