eval

python九课——1

血红的双手。 提交于 2019-12-04 07:07:58
#temoerature changeTempStr = input("请输入带有符号的温度值")if TempStr[-1] in ['F', 'f']: C = (eval(TempStr[0:-1]) - 32) / 1.8 print("转化后的温度{:.2f}C".format(C))elif TempStr[-1] in ['C', 'c']: F = 1.8 * eval(TempStr[0:-1]) + 32 print("转化后的温度{:.2f}F".format(F))else: print("输入错误")python要求代码缩进的长度要一致单行注释用#多行注释 ''' '''命名规则 首字母不能为数字保留字共有33个 现在暂时学了 if elif else import print in for 字符串类由一对单引号或者一对双引号表示列表类型默认是有[]的索引vs切片索引返回单个字符使用[]获取字符串中第一个字符[-1]表示获取倒数第一个字符切片:返回一段子串[1:3]取1,2 [0,-1]从0开始但是不到-1的字符串字符串有两种表示方法:正向递增序号和反向递减序号 正向递增序号: 0 1 2 3 4 ..... 反向递减序号: ...-5 -4 -3 -2 -1使用in来判断一个元素是否在列表中评估函数:eval能去掉参数最外侧的引号并执行余下语句

Best way to convert JSON data to an object in JavaScript?

允我心安 提交于 2019-12-04 06:55:20
问题 I am currently using eval in JavaScript to convert JSON data returned from the server into an object. eval ("myObject="+data); I've been told that eval is 'evil' and can open up big security problems. I'm wondering - is using eval to convert JSON data to an object the accepted practice? Or is there a better way? 回答1: The reason eval is considered a bad practice is that user can evaluate anything that is sent from the server. This means if you have comments forum and the user submits some

eval in function scope (accessing function args)

流过昼夜 提交于 2019-12-04 06:35:29
问题 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

Eval(), what's the point?

那年仲夏 提交于 2019-12-04 05:49:51
The Official Documentation regarding eval() as function, says: Among other things, this can be useful for storing code in a database text field for later execution. I'm seriously confused about that. Is PHP Documentation suggesting to store PHP lines into databases? What? Isn't that something freaking unsafe? What if i know that in the database there's a string that is executed as PHP? Isn't that extremely dangerous? I just need of an Sql injection to do whatever i want to that site, whatever i want . I can delete the entire database, i can get everything from the script, i can do everything.

Redisson分布式锁实现

99封情书 提交于 2019-12-04 05:47:33
转: 分布式锁和Redisson实现 概述 分布式系统有一个著名的理论CAP,指在一个分布式系统中,最多只能同时满足一致性(Consistency)、可用性(Availability)和分区容错性(Partition tolerance)这三项中的两项。所以在设计系统时,往往需要权衡,在CAP中作选择。当然,这个理论也并不一定完美,不同系统对CAP的要求级别不一样,选择需要考虑方方面面。 在微服务系统中,一个请求存在多级跨服务调用,往往需要牺牲强一致性老保证系统高可用,比如通过分布式事务,异步消息等手段完成。但还是有的场景,需要阻塞所有节点的所有线程,对共享资源的访问。比如并发时“超卖”和“余额减为负数”等情况。 本地锁可以通过语言本身支持,要实现分布式锁,就必须依赖中间件,数据库、redis、zookeeper等。 分布式锁特性 不管使用什么中间件,有几点是实现分布式锁必须要考虑到的。 互斥 :互斥好像是必须的,否则怎么叫锁。 死锁 : 如果一个线程获得锁,然后挂了,并没有释放锁,致使其他节点(线程)永远无法获取锁,这就是死锁。分布式锁必须做到避免死锁。 性能 : 高并发分布式系统中,线程互斥等待会成为性能瓶颈,需要好的中间件和实现来保证性能。 锁特性 :考虑到复杂的场景,分布式锁不能只是加锁,然后一直等待。最好实现如Java Lock的一些功能如:锁判断,超时设置,可重入性等。

execute a javascript code inside a json object?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 05:43:19
is there away? so something like: { key1 : "val1", key2: "val2", some_code: "document.getElementById("someid").innerHTML='test';" } So some_code would be executed without any user intervention? darioo No. First of all, your example isn't valid JSON. Try it out at JSON validator . Second of all, JSON is a data exchange standard and when properly parsed, any text that inside of it that is some code will not be executed. Read on JSON security issues . Rule of thumb: don't use JavaScript eval function, rather use a ready made parser such as Douglas Crockford's JSON evaluator . This would not be

In R6RS Scheme, is there a way to get the current environment for use with eval?

我怕爱的太早我们不能终老 提交于 2019-12-04 05:35:01
Is there any way in R6RS Scheme to obtain the current environment and then pass it as the second argument to eval ? For example, what should the question marks be for the following expression to return 9? (let ((x 4) (y 5)) (eval '(+ x y) ???)) No, there is no such thing in R6RS. Some rare implementations might support something like that, but in the overwhelming majority (including eval in other languages!) this cannot be done. The reason for that is simple: it breaks compilation, since it leads to making two functions distinguishable based on local names, and in some cases can also prohibit

Ruby 1.9.3 define var with eval

我的梦境 提交于 2019-12-04 05:25:41
问题 I am writing something like REPL in Ruby and I need to define vars on the run. I figured it out that I should use eval, but here is excerpt from irb session to test it. In 1.9.3 (That would work in 1.8) > eval 'a = 3' => 3 > a => NameError: undefined local variable or method `a' for main:Object They changed it in 1.9 to: > eval 'a = 3' => 3 > eval 'a' => 3 So seems like changed it since 1.9. How can I define vars in 1.9.3 using eval (or something similar)? 回答1: IRB is lying to you. This as a

Converting python string into bytes directly without eval()

ⅰ亾dé卋堺 提交于 2019-12-04 05:19:47
问题 eval() seems to be dangerous to use when processing unknown strings, which is what a part of my project is doing. For my project I have a string, called: stringAsByte = "b'a'" I've tried to do the following to convert that string directly (without using eval): byteRepresentation = str.encode(stringAsByte) print(byteRepresentation) # prints b"b'a'" Clearly, that didn't work, so instead of doing: byteRepresentation = eval(stringAsByte) # Uses eval! print(byteRepresentation) # prints b'a' Is

global.eval is not able to visit variables in the lexical scope. Does the behavior comply ECMAScript standard?

China☆狼群 提交于 2019-12-04 05:03:11
问题 I have a JavaScript file, e.js var global = Function('return this')(); var i = 1; console.log(eval("100-1")); console.log(eval("i")); console.log(global.eval("100-1")); console.log(global.eval("i")); When I execute it by V8: $ node e.js 99 1 99 undefined:1 i ^ ReferenceError: i is not defined at eval (eval at <anonymous> (/private/tmp/xxxx/e.js:8:20), <anonymous>:1:1) at eval (native) at Object.<anonymous> (/private/tmp/xxxx/e.js:8:20) at Module._compile (module.js:456:26) at Object.Module.