eval

Eval check for DBNull doesnt work

霸气de小男生 提交于 2019-12-18 06:49:20
问题 <%# Eval("Description") == DBNull.Value ? "empty" : "notempty"%> is showing always 'notempty' even there is null in that field in DB (type of varchar(), null) ... Tried also checking for empty string: <%# Eval("Description") == "" ? "empty" : "notempty"%> and it always displays notempty... what's wrong here?? 回答1: There is a difference between DBNull.Value and null . It is possible the field is returning null . Try <%# Eval("Description") == null ? "empty" : "notempty"%> Also if the field

Python 中的异常及其处理

非 Y 不嫁゛ 提交于 2019-12-18 05:56:48
1、为什么要有异常处理呢? 下面是一个例子 num = eval ( input ( "请输入一个数字" ) ) print ( num ** 2 ) 这个代码很简单,让用户输入一个数字,然后输出它的平方。 但是如果用户输入的不是数字,而是一个字符呢? 这时,程序就会报错,但是这样对于那些不熟悉程序的人,在使用这款 软件的时候,他不小心输入了一个字符,而程序却像图片中那样终止程序,并且输出一段不知道意思的文字,显然是不太友好的。 num = eval ( input ( "请输入一个数字" ) ) if ( num 是一个数字 ) : print ( num ** 2 ) else : print ( "您输入的不是数字" ) 而所谓的异常处理,就是 不使用 if, 而使用 try,except来捕获异常,并且对异常进行处理,来避免出现像最上面的那个图片那样输出一大堆用户不知所云的东西 try : num = eval ( input ( "请输入一个数字" ) ) print ( num ** 2 ) except : print ( "您输入的不是数字" ) 这样用户不会不知所云。 2、异常处理的基本使用 try : num = eval ( input ( "请输入一个数字" ) ) print ( num ** 2 ) except : print ( "您输入的不是数字"

Why is `input` in Python 3 throwing NameError: name… is not defined [duplicate]

a 夏天 提交于 2019-12-18 05:44:28
问题 This question already has answers here : input() error - NameError: name '…' is not defined (12 answers) Closed last month . I have a string variable test , in Python 2.x this works fine. test = raw_input("enter the test") print test But in Python 3.x, I do: test = input("enter the test") print test with the input string sdas , and I get an error message Traceback (most recent call last): File "/home/ananiev/PycharmProjects/PigLatin/main.py", line 5, in <module> test = input("enter the test")

Is using javascript eval() safe for simple calculations in inputs?

夙愿已清 提交于 2019-12-18 05:44:23
问题 I would like to allow user to perform simple calculations in the text inputs, so that typing 2*5 will result in 10. I'm replacing everything but digits with an empty string and then make calculation using eval(). This seems easier and probably faster then parsing it manually. It's often being said that eval() is unsafe, so I would like to hear is there any danger or drawback of using it in this situation. function (input) { value = input.value.replace(/[^-\d/*+.]/g, ''); input.value=eval

Why is Python's eval() rejecting this multiline string, and how can I fix it?

删除回忆录丶 提交于 2019-12-18 05:44:22
问题 I am attempting to eval the following tab-indented string: '''for index in range(10): os.system("echo " + str(index) + "") ''' I get, "There was an error: invalid syntax , line 1" What is it complaining about? Do I need to indent to match the eval() statement, or write it to a string file or temp file and execute that, or something else? Thanks, 回答1: eval evaluates stuff like 5+3 exec executes stuff like for ... >>> eval("for x in range(3):print x") Traceback (most recent call last): File "

F# equivalent to Eval

心已入冬 提交于 2019-12-18 04:38:15
问题 Is there an F# equivalent to eval? My intent is to have my app load a small code sample from a file and essentially let file = "c:\mysample" let sample = loadFromFile file let results = eval(sample) I am new to F# and trying to figure out some of the limitations before I apply it to a project. Thank you 回答1: There is no function that would allow you to do this directly. However, when you want to compile an F# source file programatically, you can invoke the F# compiler from your application.

python运算符和常用数据类型转换

血红的双手。 提交于 2019-12-18 02:24:51
运算符 算术运算符 运算符 描述 实例 + 加 两个对象相加 a + b 输出结果 30 - 减 得到负数或是一个数减去另一个数 a - b 输出结果 -10 * 乘 两个数相乘或是返回一个被重复若干次的字符串 a * b 输出结果 200 / 除 b / a 输出结果 2 // 取整除 返回商的整数部分 9//2 输出结果 4 , 9.0//2.0 输出结果 4.0 % 取余 返回除法的余数 b % a 输出结果 0 ** 指数 a**b 为10的20次方, 输出结果 100000000000000000000 注意:混合运算时,优先级顺序为: ** 高于 * / % // 高于 + - ,为了避免歧义,建议使用 () 来0处理运算符优先级。 并且,不同类 型的数字在进行混合运算时,整数将会转 换成浮点数进行运算。 # + 加 两个对象相加 a + b 输出结果 30 # - 减 得到负数或是一个数减去另一个数 a - b 输出结果 -10 # * 乘 两个数相乘或是返回一个被重复若干次的字符串 a * b 输出结果 200 # / 除 b / a 输出结果 2 # 请输入第一个数字a: a = int(input("请输入第一个数字a:")) b = int(input("请输入第二个数字b:")) # 加法 ret1 = a + b print("加法运算结果:%d" %

What's alternative of eval function?

自作多情 提交于 2019-12-18 01:16:26
问题 I use eval() in my current project like this: if (class_exists($class_name)) //$class_name depends on user input eval($class_name.'::MyStaticMethod()'); eval() is executed if and only if class with the name $class_name exists so it's kinda safe, but I still don't think that this is the best solution. Can I do the same what code above does without eval() ? 回答1: I have recently answered this question. The last part of my answer perfectly answers this question and is much more useful for future

Alternatives for Javascript eval [duplicate]

岁酱吖の 提交于 2019-12-18 01:12:43
问题 This question already has answers here : What are the Alternatives to eval in JavaScript? (9 answers) Closed 4 years ago . Mozilla's Content Security Policy disallows the use of javascript eval function as well as inline scripts. They claim that all instances of eval can be replaced by another (hopefully safer) function. I agree in most scenarios, Javascript eval can be replaced, but I'm not sure whether the replacement is possible for every case. My question is twofold: Is there a generic

Alternatives for Javascript eval [duplicate]

风流意气都作罢 提交于 2019-12-18 01:12:07
问题 This question already has answers here : What are the Alternatives to eval in JavaScript? (9 answers) Closed 4 years ago . Mozilla's Content Security Policy disallows the use of javascript eval function as well as inline scripts. They claim that all instances of eval can be replaced by another (hopefully safer) function. I agree in most scenarios, Javascript eval can be replaced, but I'm not sure whether the replacement is possible for every case. My question is twofold: Is there a generic