eval

Embedding arbitrary objects in Clojure code

亡梦爱人 提交于 2019-12-22 06:38:28
问题 I want to embed a Java object (in this case a BufferedImage) in Clojure code that can be eval d later. Creating the code works fine: (defn f [image] `(.getRGB ~image 0 0)) => #'user/f (f some-buffered-image) => (.getRGB #<BufferedImage BufferedImage@5527f4f9: type = 2 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=ff000000 IntegerInterleavedRaster: width = 256 height = 256 #Bands = 4 xOff = 0 yOff = 0 dataOffset[0] 0> 0 0) However you get an exception when trying to eval it: (eval

Python - Evaluate math expression within string [duplicate]

青春壹個敷衍的年華 提交于 2019-12-22 04:32:38
问题 This question already has answers here : Evaluating a mathematical expression in a string (11 answers) Closed 5 months ago . I have a question concerning evaluation of math expression within a string. For example my string is following: my_str='I have 6 * (2 + 3) apples' I am wondering how to evaluate this string and get the following result: 'I have 30 apples' Is the any way to do this? Thanks in advance. P.S. python's eval function does not help in this case. It raised an error, when trying

What is the difference between locals and globals when using Python's eval()?

泪湿孤枕 提交于 2019-12-22 03:23:04
问题 Why does it make a difference if variables are passed as globals or as locals to Python's function eval()? As also described in the documenation, Python will copy __builtins__ to globals, if not given explicitly. But there must be also some other difference which I cannot see. Consider the following example function. It takes a string code and returns a function object. Builtins are not allowed (e.g. abs() ), but all functions from the math package. def make_fn(code): import math ALLOWED

[停更]莫烦python中的'tf.stop_gradient'不太理解,于是转载mark[停更]

独自空忆成欢 提交于 2019-12-22 00:20:36
莫烦python《DDPG》代码中的’tf.stop_gradient()'不太理解,于是转载这篇好文。虽然还是没大懂,但是觉得有必要做个记录,方便以后学习。 以下内容均为转载内容,稍有改动: 引子 DQN中为什么要对q_target进行stop_gradient啊?这个函数在TensorFlow中还是很重要的,所以我们利用DQN的代码实例来说明该函数的作用。下面对其中的关键代码进行分析: No stop_gradient 这个版本就是人们写得相对较多的版本了,话不多说,直接上代码: . . . self . q_target = tf . placeholder ( tf . float32 , [ None , self . n_actions ] , name = 'Q_target' ) # for calculating loss . . . with tf . variable_scope ( 'loss' ) : self . loss = tf . reduce_mean ( tf . squared_difference ( self . q_target , self . q_eval ) ) with tf . variable_scope ( 'train' ) : self . _train_op = tf . train .

Find answer to string equation without using eval()

喜夏-厌秋 提交于 2019-12-21 23:26:40
问题 I need a way of taking an equation given as a string and finding it's mathematical answer, the big caveat is that I can't use eval(). I know the equation will only ever contain numbers, the four mathematical operators (i.e. * / + -) and parentheses, it may or may not have spaces in the string. Here's a couple of examples. 4 * 4 4+6/3 (3 / 2)*(4+8) (4+8) * 2 I'm guessing that it's going to have to be done with some kind of regex? 回答1: Math expressions aren't regular. They're context-free. Your

dplyr mutate specific columns by evaluating lookup cell value

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 15:48:22
问题 I have explored various options using quosures, symbols, and evaluation, but I can't seem to get the right syntax. Here is an example dataframe. data.frame("A" = letters[1:4], "B" = letters[26:23], "C" = letters[c(1,3,5,7)], "D" = letters[c(2,4,6,8)], "pastecols" = c("B, C","B, D", "B, C, D", NA)) A B C D pastecols 1 a z a b B, C 2 b y c d B, D 3 c x e f B, C, D 4 d w g h <NA> Now suppose I want to paste values from different columns based on the lookup string in pastecols, and I always want

Webpack_(第三章)_SourceMap的配置

岁酱吖の 提交于 2019-12-21 15:36:20
SourceMap的配置 什么是SourceMap? 在webpack.config.js,在开发者模式 mode: "development" 下,默认SourceMap已经配置好,所以我们先关闭SourceMap mode: "development", devtool: 'none', 重新运行打包就可以了,发现运行成功,那么SourceMap到底是什么东西呢? 如果故意定义错误语法,例如 consele.log('hello word!') ,打包不会有问题,页面运行会出错 想看哪里出了错,就会点击右侧提示看看代码哪里报错 但是这是我们打包出来dist文件下main.js的代码,可是我们希望当代码写错了的时候,不要告诉我们是打包的文件里到底是哪一行代码,我们想要知道原代码中里哪一句代码错了。怎么办呢,我们就可以通过SourceMap来做这样的事情。 SourceMap是一个映射关系,她知道打包出来的js文件对应的原代码,通过这个映射关系我们就可以知道是哪一行代码出错了 如何使用这种映射关系呢 只需要在webpack.config.js的devtool配置为source-map就可以了 打包运行,点击报错 就可以看到是index.js文件报错了。 这就是SourceMap的意义,我们看报错,是想看原代码的报错,而不是打包之后的文件报错 官网学习:DOCUMENTATION—

Makefile Variable Assignment Executes Early

微笑、不失礼 提交于 2019-12-21 12:32:15
问题 I have a Makefile rule that requires storing the results from shell commands into variables for later use. For some reason, it seems that the $(shell) call executes as soon as my rule is match, as opposed to when it is encountered during execution. The file is as follows: TMPDEV=/tmp/disk.img $(TMPDEV): fallocate -l 806354944 $(TMPDEV) sudo parted --script $(TMPDEV) unit s mklabel msdos \ mkpart primary fat16 2048 526335 \ mkpart primary fat32 526336 1050623 \ mkpart primary NTFS 1050624

execute a javascript code inside a json object?

本小妞迷上赌 提交于 2019-12-21 12:22:27
问题 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? 回答1: 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

LR参数和变量

大兔子大兔子 提交于 2019-12-21 10:24:19
一、参数: 1. 在LR函数中可以直接使用参数。参数必须在双引号“”中才能应用。大部分情况下,可以直接用参数代替函数中双引号内的数据。如下使用方法: lr_save_string(" http://www.baidu.com","url "); web_url("test","URL={url}",LAST); 2. 参数是全局的,同一个脚本的任何一个action都能使用。 3. 在VuGen中,默认带有{}的字符串为参数。 4. 将一个字符串、数字、日期写入一个参数保存的函数分别为:lr_save_string(); lr_save_int(); lr_save_datetime(); 5. 参数数组(LR9.x后出现)的三个函数: lr_paramarr_len("param_name");参数数组的长度。(既param_name_count) lr_paramarr_idx("param_name",i);数组中编号为i的参数值。 lr_paramarr_random("param_name");数组中随机一个参数值。 二、变量 1. 变量是C语言的,无法直接运用在系统函数中。如下使用方法: char url[100]; strcpy(url,"URL=http://www.baidu.com"); web_url("test",url,LAST); 2. 变量是局部的