eval

How do you evaluate a string as a clojure expression?

℡╲_俬逩灬. 提交于 2019-11-28 10:41:19
How would I get something similar to the following?: (evaluate-text "(+ 1 2)") ; resolves to 3 (load-string "(+ 1 2)") user> (eval (read-string "(+ 1 2)")) 3 You probably shouldn't ever need to do this. Macros and fns make this kind of thing unnecessary 99% of the time. This is quite brittle, and can be unsafe if these strings are coming from user input, and so on. How similar does it have to be? Clojure's eval works on lists, so: (eval (list + 1 2)) #=> 3 来源: https://stackoverflow.com/questions/1885448/how-do-you-evaluate-a-string-as-a-clojure-expression

GridView模板之使用模板编辑

做~自己de王妃 提交于 2019-11-28 10:30:34
使用模板编辑的一个最重要的原因是为了提供更好的编辑体验。 实现编辑最简便的方式是加入一个ShowEditButton的属性值为真(或者GridView.AutoGrnerateEditButton属性为真)的CommandField列。不管用哪种方法,都必须以用于显示编辑命令的专用列结束。起初,这个列将挨着每条记录显示名为编辑的链接。当用户单击编辑链接时,该行中的所有列由标记变成了文本框(只读字段除外)。 在模板列中,可以使用EditItem Template定义编辑控件以及它们的布局,不过这个过程有点费劲。 下面这个编辑模板允许你编辑单个字段---Notes字段 <EditItemTemplate> <b> <%# Eval("TitleOfCourse") %> - <%# Eval("EmployeeID") %> <%# Eval("FirstName") %> <%# Eval("LastName") %> </b> <hr /> <small><i> <%# Eval("Address") %><br /> <%# Eval("City") %>, <%# Eval("Country") %>, <%# Eval("PostalCode") %><br /> <%# Eval("HomePhone") %></i> <br /><br /> <asp:TextBox

GridView模板之使用模板编辑

耗尽温柔 提交于 2019-11-28 10:29:55
使用模板编辑的一个最重要的原因是为了提供更好的编辑体验。 实现编辑最简便的方式是加入一个ShowEditButton的属性值为真(或者GridView.AutoGrnerateEditButton属性为真)的CommandField列。不管用哪种方法,都必须以用于显示编辑命令的专用列结束。起初,这个列将挨着每条记录显示名为编辑的链接。当用户单击编辑链接时,该行中的所有列由标记变成了文本框(只读字段除外)。 在模板列中,可以使用EditItem Template定义编辑控件以及它们的布局,不过这个过程有点费劲。 下面这个编辑模板允许你编辑单个字段---Notes字段 < EditItemTemplate > < b > <% # Eval ( " TitleOfCourse " ) %> - <% # Eval ( " EmployeeID " ) %> <% # Eval ( " FirstName " ) %> <% # Eval ( " LastName " ) %> </ b > < hr /> < small >< i > <% # Eval ( " Address " ) %> < br /> <% # Eval ( " City " ) %> , <% # Eval ( " Country " ) %> , <% # Eval ( " PostalCode " ) %>

Dynamic variables matlab

妖精的绣舞 提交于 2019-11-28 10:19:03
问题 How can I access to dynamic variables in Matlab? I search for similar question but I didn't find. Example (simplified): for i=1:1 aux3=(i-1)*50; delay_64_264(1,i) = mean(delay_64_264_', num2str(aux3), ' (:,3)*100; end What I want to do is mean of column 3 from variable delay_64_264_0 . Anyone can help me? Thank you very much 回答1: You can use eval(). But I recommend not doing this at all. Use a multidimensional array, rather than lots of variables with slightly different names. 回答2: To follow

Why not eval() JSON?

拜拜、爱过 提交于 2019-11-28 10:13:30
As far as I know it is considered bad practice to eval() JSON objects in JavaScript, because of security. I can understand this concern if the JSON comes from another server. But if the JSON is provided by my own server and is created using PHP's json_encode (let us assume it is not buggy), is it legitimate to simply use eval() to read the JSON in JS or are there any security problem I currently can't think of? I really don't want to deal with dynamically loading a JSON parser and would be glad to simply use eval() . PS: I will obviously use the native JSON object if it is available, but want

内置函数:exec、eval、compile

别说谁变了你拦得住时间么 提交于 2019-11-28 10:02:42
eval:将字符串内的代码执行,有返回值,用于简单的计算exec:将字符串内的代码执行,没有返回值,用于简单的逻辑判断   均可以读取文件进行执行 info_str = '1+2+3' couunt = eval(info_str) couunt1 = exec(info_str) print(couunt)#返回6 print(couunt1)#无返回值 jud =''' def func(a,b): return a if a>b else b func(1,2) ''' exec(jud)#无返回值 jud1 =''' for i in range(10): print(i) ''' exec(jud1)#返回0-9 compile:将源代码编译成可以由exec()或eval()执行的代码对象。源代码可以表示Python模块、语句或表达式。'single'编译单个(交互的)语句 code = '1+2+3' cpe = compile(code,'','eval') print(eval(cpe)) code = 'for i in range(10):print(i)' cpe = compile(code,'','exec') exec(cpe) code = 'name = input("请输入你的姓名:")' cpe = compile(code,'','single

Question about eval in PHP 5

有些话、适合烂在心里 提交于 2019-11-28 09:56:39
问题 I have been doing PHP stuff for almost one year and I have never used the function eval() though I know the usage of it. But I found many questions about it in SO.So can someone show me a simple example in which it's necessary to use eval() ?And is it a good or bad practice? 回答1: Using eval() is a bad practice, and if it turns out to be necessary to achieve something, that is usually the sign of a underlying design error. I can't think of any situation where it is necessary to use eval() . (i

内置函数1

霸气de小男生 提交于 2019-11-28 09:53:22
exec和eval exec和evak都可以执行 字符串类型的代码 evak只能用在你明确知道你要执行的代码是什么 eval 有返回值,——适合有结果的简单计算 exec 没有返回。——适合简单的流程控制 exec( 'print(123)') eval('print(123)') print(eval('1+2+3+4'))#有返回值 print(exec('1+2+3+4'))#没有返回值 View Code 例如exec #应用exec code = '''for i in range(8): print('*'*i)''' exec(code) View Code complie 将字符串代码进行编译,代码对象能够通过exec语句来执行或者eval来求值。 compile()用法 '''compile(参数:及字符串或者ast对象,'代码文件名称:从文件里面读代码时,否则为空',执行方式:eval或者exec)''' code1 = '1+2+3' h = compile(code1,'','eval') print(eval(h)) View Code 注意在交互式时,需要把exec方式改为single就行。 来源: https://www.cnblogs.com/zly9527/p/11403790.html

JavaScript eval() “syntax error” on parsing a function string

社会主义新天地 提交于 2019-11-28 09:53:11
I have a bit of JavaScript code that is specified in a configuration file on the server-side. Since I can't specify a JavaScript function in the configuration language (Lua), I have it as a string. The server returns the string in some JSON and I have the client interpret it using a clean-up function: parse_fields = function(fields) { for (var i = 0; i < fields.length; ++i) { if (fields[i].sortType) { sort_string = fields[i].sortType; fields[i].sortType = eval(sort_string); } return fields; } }; So basically it just evaluates sortType if it exists. The problem is that Firebug is reporting a

python温度转换代码

五迷三道 提交于 2019-11-28 09:42:43
#TempConvert.py TempStr=input("请输入带有符号的温度值:")#赋值TempStr,括号里面的是提示 if TempStr[-1] in ['F','f']:#假如字符串最后一个字符是F或者f C=(eval(TempStr[0:-1])-32)/1.8#第一个字符到最后一个字符之前的所有字符,也就是温度值,eval函数是脱掉字符串结构,运行公式 print("转换后的温度是{:.2f}C".format(C))、#输出结果,保留最后两位小数,是C的格式化 elif TempStr[-1] in ['C','c']:#else if最后一个字符是C或者c F=1.8*eval(TempStr[0:-1])+32#这个括号加括号的表达,其实从里到外的顺序来看就不会混乱 print("转换后的温度是{:.2f}F".format(F))#输出华氏温度 else:#以上两个if都不符合 print("输入格式错误")#输出提示文字    来源: https://www.cnblogs.com/saludmoment/p/11403520.html