eval

Malformed String ValueError ast.literal_eval() with String representation of Tuple

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to read in a string representation of a Tuple from a file, and add the tuple to a list. Here's the relevant code. raw_data = userfile.read().split('\n') for a in raw_data : print a btc_history.append(ast.literal_eval(a)) Here is the output: (Decimal('11.66985'), Decimal('0E-8')) Traceback (most recent call last): File "./goxnotify.py", line 74, in <module> main() File "./goxnotify.py", line 68, in main local.load_user_file(username,btc_history) File "/home/unix-dude/Code/GoxNotify/local_functions.py", line 53, in load_user_file

What does Python's eval() do?

匿名 (未验证) 提交于 2019-12-03 02:12:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In the book that I am reading on Python, it keeps using the code eval(input('blah')) I read the documentation, and I understand it, but I still do not see how it changes the input() function. What does it do? Can someone explain? 回答1: The eval function lets a python program run python code within itself. eval example (interactive shell): >>> x = 1 >>> eval('x + 1') 2 >>> eval('x') 1 回答2: eval() interprets a string as code. The reason why so many people have warned you about using this is because a user can use this as an option to run code

Understanding ASP.NET Eval() and Bind()

匿名 (未验证) 提交于 2019-12-03 02:12:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Can anyone show me some absolutely minimal ASP.NET code to understand Eval() and Bind() ? It is best if you provide me with two separate code-snippets or may be web-links. 回答1: For read-only controls they are the same. For 2 way databinding, using a datasource in which you want to update, insert, etc with declarative databinding, you'll need to use Bind . Imagine for example a GridView with a ItemTemplate and EditItemTemplate . If you use Bind or Eval in the ItemTemplate , there will be no difference. If you use Eval in the EditItemTemplate

Understanding ASP.NET Eval() and Bind()

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Can anyone show me some absolutely minimal ASP.NET code to understand Eval() and Bind() ? It is best if you provide me with two separate code-snippets or may be web-links. 回答1: For read-only controls they are the same. For 2 way databinding, using a datasource in which you want to update, insert, etc with declarative databinding, you'll need to use Bind . Imagine for example a GridView with a ItemTemplate and EditItemTemplate . If you use Bind or Eval in the ItemTemplate , there will be no difference. If you use Eval in the EditItemTemplate

eval SyntaxError: invalid syntax in python

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to assign : x0='123' x1='123' x2='123' x3='123' x4='123' x5='123' x6='123' x7='123' x8='123' x9='123' I write the code to express that i can get the output of a string 123 when input x1 or x8 . for i in range(0,10): eval("x"+str(i)+"='123'") Traceback (most recent call last): File "<stdin>", line 2, in <module> File "<string>", line 1 x0='123' ^ SyntaxError: invalid syntax How i can do that way? 回答1: For dynamic execution of statements use exec statement. >>> exec('y=3') >>> y 3 Eval Usgae: eval(expression) The expression argument is

What&#039;s the difference between eval, exec, and compile in Python?

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've been looking at dynamic evaluation of Python code, and come across the eval() and compile() functions, and the exec statement. Can someone please explain the difference between eval and exec , and how the different modes of compile() fit in? 回答1: The short answer, or TL;DR Basically, eval is used to eval uate a single dynamically generated Python expression, and exec is used to exec ute dynamically generated Python code only for its side effects. eval and exec have these two differences: eval accepts only a single expression , exec can

ValueError: malformed string when using ast.literal_eval

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: It is widely known that using eval() is a potential security risk so the use of ast.literal_eval(node_or_string) is promoted However In python 2.7 it returns ValueError: malformed string when running this example: >>> ast.literal_eval("4 + 9") Whereas in python 3.3 this example works as expected: >>> ast.literal_eval('4+9') 13 Why does it run on python 3 and not python 2? How can I fix it in python 2.7 without using the risky eval() function? 回答1: The reason this doesn’t work on Python 2 lies in its implementation of literal_eval . The

Why is using 'eval' a bad practice?

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am using the following class to easily store data of my songs. class Song : """The class to store the details of each song""" attsToStore =( 'Name' , 'Artist' , 'Album' , 'Genre' , 'Location' ) def __init__ ( self ): for att in self . attsToStore : exec 'self.%s=None' %( att . lower ()) in locals () def setDetail ( self , key , val ): if key in self . attsToStore : exec 'self.%s=val' %( key . lower ()) in locals () I feel that this is just much more extensible than writing out an if/else block. However, eval seems to be

Is &#039;eval&#039; supposed to be nasty?

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have been using eval feature of ruby many a times. But I have heard people saying eval s are nasty. When asked, why and how, I could never get a convincing reason not to use it. Are they really nasty? If yes, in what way? What are possible "safer" options to eval? 回答1: If you are eval ing a string submitted by, or modifiable by the user, this is tantamount to allowing arbitrary code execution. Imagine if the string contained an OS call to rm -rf / or similar. That said, in situations where you know the strings are appropriately constrained

How to add a Linux kernel driver module as a Buildroot package?

匿名 (未验证) 提交于 2019-12-03 02:01:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am currently building an Embedded Linux for my Zybo Board from Xilinx. For this I use Buildroot. Now I want to add a driver , written in C, which can be used by a user program to write to some specific registers, enabling it to control some LEDs. When I checked the manual , it basically says the first thing to do is create a Config.in in a new package folder, where you write some text explaining the driver. Okay, I did that. But now the makefile: I don't quite understand what needs to be in there. Is it just a compile command like gcc -o