eval

Risks of using PHP eval [duplicate]

孤街醉人 提交于 2019-12-02 17:20:05
问题 This question already has answers here : Closed 8 years ago . Possible Duplicates: When (if ever) is eval NOT evil? when is eval evil in php? Since I found no other way of executing a string from an external file as code, I resorted to utilizing eval(). I am not asking about any code in particular, since examples in my use-case scenario would be trivial - what I want to know is what are the dangers of using eval in php code. I did some research on the subject, but I couldn't find any answer

测验3: 基本数据类型 (第3周)

孤者浪人 提交于 2019-12-02 12:40:38
测验3: 基本数据类型 (第3周) 文章目录 测验3: 基本数据类型 (第3周) 单选题 程序题 这是python123官网上联合MOOC的Python程序设计(第10期)答案 单选题 程序题 基础题,计算平方根,用format进行输出控制,右对齐,不足30位用 + 补齐 对format的使用有疑问的,可以翻看嵩天老师python语言程序设计基础(第二版)第86页的format方法的格式控制 a=eval(input()) b=pow(a,0.5) print("{0:+>30.3f}".format(b)) 基础题,调用 s p l i t split s p l i t 函数进行分割,再用加号连接字符串即可 这里要注意一点,不能使用eval,因为eval读取后会把连接符’-'作为字符串的加减从而造成错误,直接使用input即可 a=input() b=a.split('-') c=b[0]+'+'+b[-1] print(c) 来源: https://blog.csdn.net/qq_42582489/article/details/102761078

converting string to tuple in python

妖精的绣舞 提交于 2019-12-02 12:22:55
问题 I have a string returnd from a software like "('mono')" from that I needed to convert string to tuple . that I was thinking using ast.literal_eval("('mono')") but it is saying malformed string. 回答1: Since you want tuples, you must expect lists of more than element in some cases. Unfortunately you don't give examples beyond the trivial (mono) , so we have to guess. Here's my guess: "(mono)" "(two,elements)" "(even,more,elements)" If all your data looks like this, turn it into a list by

Evaluate dataframe$column expression stored as a string value

可紊 提交于 2019-12-02 12:01:29
Can a string of the form below be evaluated so that it is equivalent to the same "literal" expression? Example data and code: df.name = data.frame(col1 = 1:5, col2 = LETTERS[seq(1:5)], col3 = letters[seq(1:5)], stringsAsFactors = FALSE) col.name = "col2" row.num = "4" var1 = str_c("df.name$", col.name,"[",row.num,"]") > var1 [1] "df.name$col2[4]" The literal works as expected > df.name$col2[4] [1] D get() is not equivalent: get(var1) ## Error in get(var1) : object 'df.name$col2[4]' not found This form of get() "works" but does not solve the problem get("df.name")$col2[4] [1] D Per other posts

Python eval的用法及注意事项

我的梦境 提交于 2019-12-02 11:43:57
eval是Python的一个内置函数,这个函数的作用是,返回传入字符串的表达式的结果。想象一下变量赋值时,将等号右边的表达式写成字符串的格式,将这个字符串作为eval的参数,eval的返回值就是这个表达式的结果。 python中eval函数的用法十分的灵活,但也十分危险,安全性是其最大的缺点。本文从灵活性和危险性两方面介绍eval。 1、强大之处 举几个例子感受一下,字符串与list、tuple、dict的转化。 强大吧,给个字符串给eval,eval给你一个表达式返回值。 eval的语法格式如下: expression : 字符串 globals : 变量作用域,全局命名空间,如果被提供,则必须是一个字典对象。 locals : 变量作用域,局部命名空间,如果被提供,可以是任何映射对象。 结合globals和locals看看几个例子 传递globals参数值为{“age”:1822}, 输出结果 再加上locals变量 根据上面两个例子可以看到当locals参数为空,globals参数不为空时,查找globals参数中是否存在变量,并计算。 当两个参数都不为空时,先查找locals参数,再查找globals参数,locals参数中同名变量会覆盖globals中的变量。 2、危险之处 eval虽然方便,但是要注意安全性,可以将字符串转成表达式并执行,就可以利用执行系统命令

eval

穿精又带淫゛_ 提交于 2019-12-02 11:40:56
// eval不是专门用来解析json // 功能:将字符作为js代码执行 res = eval(res); console.log(res); // res = JSON.parse(res); }) } // var str = "1 + 1"; // console.log(eval(str)); // console.log(eval("hello")); // 在js中对象不允许直接存在,因为会将花括号作为作用域解析 // var str = '{"user":"admin"}'; // console.log(eval(str)) 来源: https://blog.csdn.net/qq_45264394/article/details/102757169

day7:python函数编写:高级内置函数(enmerate,eval,felter)

痴心易碎 提交于 2019-12-02 11:27:30
3.pyhotn中高级内置函数 (1)enmerate 返回一个可以枚举的对象,enmerate将其组成一个索引,利用它的可以同时获得索引和值 (2)eval 1)取出字符串的内容 2)将字符串str当成有效的表达式来求指并返回计算结果 # 取出字符串中的值 str = "[1,2,3,4]" eval ( str ) [ 1 , 2 , 3 , 4 ] # 计算结果 >> > x = 7 >> > eval ( '3 * x' ) 21 (3)filter过滤器 filert ( 参数 1 ,参数 2 ) 参数 1 :过滤规则的函数 参数 2 :要过滤的数据 应用案例:请过滤列表li=[1,2,3,4,5,6,7,8,9,10]大于5的数值 # @time:2019/10/26 11:35 # @Author:coco # @File:06高级内置函数.py # @software:PyCharm # enumerate的使用 li = [ 11 , 22 , 33 , 44 ] res = enumerate ( li ) list2 = list ( res ) print ( '----------list2--------' ) print ( list2 ) # dic={"a":11,"b":22} # print(list(dic.items())) # eval

is there a way to execute a function when I have its name in a string [duplicate]

爱⌒轻易说出口 提交于 2019-12-02 09:49:58
This question already has an answer here: How to execute a JavaScript function when I have its name as a string 32 answers Consider I have a name of a function which does not require any argument in a var - var fn = "foo"; Can I execute it in some or similar like this - eval(fn); It does not work. Please suggest. My definition of function will look like this - function foo() { ....do something.... } gurvinder372 try this eval(fn)(); or this eval(fn + "()"); Please do not use eval. If the function is in global scope, simply do var fn = "foo"; window[fn](); DEMO 来源: https://stackoverflow.com

eval in function scope (accessing function args)

 ̄綄美尐妖づ 提交于 2019-12-02 09:48:08
Given: abstract ABSGene type NuGene <: Genetic.ABSGene fqnn::ANN dcqnn::ANN score::Float32 end function mutate_copy{T<:ABSGene}(gene::T) all_fields_except_score = filter(x->x != :score, names(T)) all_fields_except_score = map(x->("mutate_copy(gene.$x)"),all_fields_except_score) eval(parse("$(T)("*join(all_fields_except_score,",")*")")) end ng = NuGene() mutated_ng = mutate_copy(ng) results in: ERROR: gene not defined in mutate_copy at none:4 If I just look at it as a string (prior to running parse and eval) it looks fine: "NuGene(mutate_copy(gene.fqnn),mutate_copy(gene.dcqnn))" However, eval

How to get results out of a Python exec()/eval() call?

我们两清 提交于 2019-12-02 09:37:43
问题 I want to write a tool in Python to prepare a simulation study by creating for each simulation run a folder and a configuration file with some run-specific parameters. study/ study.conf run1 run.conf run2 run.conf The tool should read the overall study configuration from a file including (1) static parameters (key-value pairs), (2) lists for iteration parameters, and (3) some small code snippets to calculate further parameters from the previous ones. The latter are run specific depending on