eval

How does str(list) work?

雨燕双飞 提交于 2019-11-27 01:54:50
问题 Why does str(list) returns how we see list on the console? How does str(list) work? (any reference to the CPython code for str(list) )? >>> x = ['abc', 'def', 'ghi'] >>> str(x) "['abc', 'def', 'ghi']" To get the original list back from the str(list) I have to: >>> from ast import literal_eval >>> x = ['abc', 'def', 'ghi'] >>> str(x) "['abc', 'def', 'ghi']" >>> list(str(x)) ['[', "'", 'a', 'b', 'c', "'", ',', ' ', "'", 'd', 'e', 'f', "'", ',', ' ', "'", 'g', 'h', 'i', "'", ']'] >>> literal

Haskell: how to evaluate a String like “1+2”

廉价感情. 提交于 2019-11-27 01:53:38
Actually I have some formula like "x + y" , which is a String . I managed to replace the x/y variable with specific values like "1.2" , which is still String type. Now I have expression like "1 + 2" . So the problem is how to evaluate a expression of a string type and get the result. ps: I wanna sth like read , that can directly convert the whole string expression instead of handling the operator (+/-,etc) case by case. Is that possible? Your question leaves a lot of room for interpretation. I'm taking a guess you aren't accustom to building a whole pipeline of lexing, parsing, maybe type

JavaScript严格模式

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 01:53:14
初步了解严格模式 一个用心良苦的语言模式设计 一、初步了解严格模式 ECMAScript 5的严格模式是采用具有限制性JavaScript变体的一种方式,从而使代码显示地“脱离马虎模式/稀松模式/懒散“模式。 为什么这么说呢?有时候忘记在作用域链上是否存在某个变量了,或者忘记在那一层作用域,但是当前作用域需要对这个似乎存在的变量赋值,在非严格模式下可以直接在当前作用域给这个变量赋值,如果在作用域链上不存在这个变量,最终这个变量会被定义到全局。 这种不严谨的代码在非严格模式下可能看起来不会有什么问题,但是对于全局变量命名会造成非常大的困扰,而且程序性能也会受到很大的挑战。 往好的方向说非严格模式对这种错误行为的静默是一种容错行为,但是这必然会带来另一种情况就是:可能在编程中写错一个变量名的赋值行为,这时候程序不能正确修改变量的值,还错误的在全局添加了一个变量,若说这是一种容错行为,显然不是一个很好的编程思想。 随着前端程序的复杂性越来越高,JavaScript这种不严谨的编码方式给代码的编写和管理带来了很大的挑战,在ES6的一些语法中就为了摒弃这种不严谨的行为出现了新的语法模式,语言设计者为了从ES5到ES6的过渡,以及为了JS语言能承担其未来的前端发展,在ES5中提出了严格模式。 严格模式的具体内容: 1.不允许使用为申明的变量: 1 "use strict" 2 a = 10;

Ruby: creating a sandboxed eval?

可紊 提交于 2019-11-27 01:19:32
问题 My Rails app has complicated rules about when a bit of content should be displayed on a page or not. I've decided to implement this by writing predicates (simple 'yes/no' functions) in Ruby and storing them in the db for subsequent eval'ing. It it pretty straightforward. My main concern is security: if a malicious somebody figures out how to write to the db, they could stick arbitrary Ruby code in the db and then ' all your base are belong to us '. So is it possible to create an 'sandboxed'

Properly handling spaces and quotes in bash completion

亡梦爱人 提交于 2019-11-27 01:17:09
问题 What is the correct/best way of handling spaces and quotes in bash completion? Here’s a simple example. I have a command called words (e.g., a dictionary lookup program) that takes various words as arguments. The supported ‘words’ may actually contain spaces, and are defined in a file called words.dat : foo bar one bar two Here’s my first suggested solution: _find_words() { search="$cur" grep -- "^$search" words.dat } _words_complete() { local IFS=$'\n' COMPREPLY=() cur="${COMP_WORDS[COMP

eval javascript, check for syntax error

一个人想着一个人 提交于 2019-11-27 01:08:21
问题 I wanted to know if it is possible to find through javascript if a call to eval() has a syntax error or undefined variable, etc... so lets say I use eval for some arbitrary javascript is there a way to capture the error output of that eval? 回答1: You can test to see if an error is indeed a SyntaxError. try { eval(code); } catch (e) { if (e instanceof SyntaxError) { alert(e.message); } } 回答2: When using try catch for catching particular type of error one should ensure that other types of

Accessing object property as string and setting its value

荒凉一梦 提交于 2019-11-27 00:06:33
问题 I have an instance of the Account class. Each account object has an owner, reference, etc. One way I can access an accounts properties is through accessors like account.Reference; but I would like to be able to access it using dynamic string selectors like: account["PropertyName"]; just like in JavaScript. So I would have account["Reference"] which would return the value, but I also would like to be able to assign a new value after that like: account["Reference"] = "124ds4EE2s"; I've noticed

openwrt: Makefile 框架分析

若如初见. 提交于 2019-11-26 23:39:41
/*--> */ /*--> */ 主 Makefile 分析 注: 1 ) make -n 可打印 makefile 执行的命令,而不执行。 2 )可以在规则的命令中增加 echo 跟踪执行进度。 顶层目录的 Makefile 是 openert 的总 Makefile ,第一个编译目标 world 是 make 的默认编译目标。 world: include $(TOPDIR)/include/host.mk ifneq ($(OPENWRT_BUILD),1) _SINGLE=export MAKEFLAGS=$(space); override OPENWRT_BUILD=1 export OPENWRT_BUILD GREP_OPTIONS= export GREP_OPTIONS include $(TOPDIR)/include/debug.mk include $(TOPDIR)/include/depends.mk include $(TOPDIR)/include/toplevel.mk else include rules.mk include $(INCLUDE_DIR)/depends.mk include $(INCLUDE_DIR)/subdir.mk include target/Makefile include package/Makefile

PHP Web 木马扫描器

这一生的挚爱 提交于 2019-11-26 23:27:35
直接放在网站根目录运行即可 <?php /**************PHP Web木马扫描器************************/ /* [+] 版本: v1.0 */ /* [+] 功能: web版php木马扫描工具 */ /* [+] 注意: 扫描出来的文件并不一定就是后门, */ /* 请自行判断、审核、对比原文件。 */ /* 如果你不确定扫出来的文件是否为后门, */ /* 欢迎你把该文件发给我进行分析。 */ /*******************************************************/ ob_start(); set_time_limit(0); $username = "t00ls"; //设置用户名 $password = "t00ls"; //设置密码 $md5 = md5(md5($username).md5($password)); $version = "PHP Web木马扫描器 v1.0"; $realpath = realpath('./'); $selfpath = $_SERVER['PHP_SELF']; $selfpath = substr($selfpath, 0, strrpos($selfpath,'/')); define('REALPATH', str_replace('//','/'

eval函数解析JSON 数据出错

↘锁芯ラ 提交于 2019-11-26 23:14:48
描述:使用eval函数解析JSON数据出错报 这个错误。 经使用debug测试才发现是我语法有问题: 没有解决前代码: var ArrayData = eval(data); 解决后代码: var JsonData = eval('('+data+')'); 为什么要 eval这里要添加 '('+data+')' 呢? 原因在于:eval本身的问题。 由于json是以”{}”的方式来开始以及结束的,在JS中,它会被当成一个语句块来处理,所以必须强制性的将它转换成一种表达式。 加上圆括号的目的是迫使eval函数在处理JavaScript代码的时候强制将括号内的表达式(expression)转化为对象,而不是作为语句(statement)来执行。举一个例子,例如对象字面量{},如若不加外层的括号,那么eval会将大括号识别为JavaScript代码块的开始和结束标记,那么{}将会被认为是执行了一句空语句。所以下面两个执行结果是不同的: alert(eval("{}"); // return undefined alert(eval("({})");// return object[Object] 来源: oschina 链接: https://my.oschina.net/u/563338/blog/392787