Тёмный

Python Eval programming tutorial 

sentdex
Подписаться 1,4 млн
Просмотров 55 тыс.
50% 1

The expression argument is parsed and evaluated as a Python expression (technically speaking, a condition list) using the globals and locals dictionaries as global and local namespace. If the globals dictionary is present and lacks ‘__builtins__’, the current globals are copied into globals before expression is parsed. This means that expression normally has full access to the standard builtins module and restricted environments are propagated. If the locals dictionary is omitted it defaults to the globals dictionary. If both dictionaries are omitted, the expression is executed in the environment where eval() is called. The return value is the result of the evaluated expression. Syntax errors are reported as exceptions.
Source: docs.python.org/3.4/library/f...
sample code: pythonprogramming.net
hkinsley.com
/ sentdex
sentdex.com
seaofbtc.com

Опубликовано:

 

22 май 2015

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 33   
@silverfluoride5073
@silverfluoride5073 4 года назад
Thank you for the video, my lecturing book is quite misunderstandable...
@sliddjur
@sliddjur 5 лет назад
So why would one use eval? I don't get it
@mamazu1995
@mamazu1995 9 лет назад
You could also do this with regex very well but this is not the point. The question I have is can you acess a function with this previously defined by yourself in the "real" code?
@viveksingh-dc7ny
@viveksingh-dc7ny 5 лет назад
I have dictionary in a list And using API to get that So should I use Eval or pickle?
@chobblegobbler6671
@chobblegobbler6671 2 года назад
Thank you, Jesse!
@cardoran6757
@cardoran6757 5 лет назад
but isn't eval just as dangerous as exec, since you can always evaluate e.g. eval("exec('x=5')")? it actually works in python 3.5 on my pc
@ramirez533
@ramirez533 4 года назад
great tutorial!
@SilverMiraii
@SilverMiraii 5 лет назад
trying to find a solution for evaluating only mathematical expressions
@Nom3x
@Nom3x 2 года назад
this is super useful
@gilbertsanchez1714
@gilbertsanchez1714 3 года назад
Thank you bro.
@GauravSingh-ku5xy
@GauravSingh-ku5xy 4 года назад
Thanks a lot
@abhishekmann
@abhishekmann 6 лет назад
list string list strin list stri list str list st list s list liste lister listeri listerin LISTERINE! So that's the secret to your pearly whites eh Harrison? :) Loved your basics series. Thank you so much
@purpleice2343
@purpleice2343 6 лет назад
String version of a dictionary is literally the same as json string... Also eval is just not really useful unless you need to have built in scripting in python program for realtime evaluation.
@JohnForbes
@JohnForbes 3 года назад
The dark side of the force is a pathway to many abilities some consider to be...unnatural.
@user-yx1pe4ny7t
@user-yx1pe4ny7t 2 года назад
while True: print(eval(input()))
@krishnasharma8674
@krishnasharma8674 3 года назад
ure explanation and mine textbook explanation are bit different hence no idea who is correct and what is the usage of EVAL? but youre video was good
@fatihabamaarouf7748
@fatihabamaarouf7748 4 года назад
m working with anaconda what s that u re using pls !
@niczwerg
@niczwerg 9 лет назад
Really?!? I wrote an extra function, that turns a string like "(1, 4, 7, 2)" into a tuple... lol... ;) Thx your tutorials are awesome!
@sentdex
@sentdex 9 лет назад
niczwerg I didn't think I would ever bother with showing eval or exec... but I find myself using them all the darn time when parsing info offline, so I figured I might as well! Glad you have enjoyed!
@niczwerg
@niczwerg 9 лет назад
sentdex Python just has so many modules and functions, that are so helpful, but I struggle to find the right ones when I need them. But I guess that's absolutely normal for a beginner in programming... So with watching your vids I learn much more about the opportunities of Python and since I also want to do some "data analysis", it helps my purposes. ;) Especially those "little" things can be a great help.....
@sentdex
@sentdex 9 лет назад
niczwerg I went years before I even learned about the json module, same with eval, exec, and pickle. Pickle just sounded silly to me, so I didn't bother with it. Also the definition made no sense to me, so I just kept working without it. Even with just knowing the simplest things in Python, there's so much you can do. I think my biggest regret worth mentioning, especially since you bring up data analysis, is ignoring Pandas. I just didn't see the point when I could do all the things Pandas did initially. Pandas is just fast as lightening, and does things that would take me hours or days to write sometimes. Definitely look into pandas if you haven't. There's some of that here: pythonprogramming.net/pandas-saving-reading-csv-file/
@niczwerg
@niczwerg 9 лет назад
Yes Pandas is already installed, its simply great. An example is the possibility of turning tick data into OHLC - that's a great feature that saves me a lot of time. But I'll watch your whole series in the next days, maybe there are some more things I can benefit from... ;) Best regards
@theglobalconflict6904
@theglobalconflict6904 4 года назад
is it possible to make my own eval() function by myself????
@kurshitha565
@kurshitha565 3 года назад
Sir can u explain print(eval('1*-2'*2)) of output 42(how it works)
@HeadInstead
@HeadInstead 3 года назад
Ha, interesting example... (but one that hopefully never will be used in real applications..) Focus on the part within the eval function first: '1*-2'*2, It is a string ('1*-2') multiplied by an integer (2). In python this means a copy of the string will be attached to the original string. So the result will be the string '1*-21*-2'. That will be evaluated in eval: 1 * -21 * -2 which equals 42 (2 * 21 basically). (note that when the string was multiplied by 3 instead of 2 the string would be '1*-21*-21*-2'.)
@kurshitha565
@kurshitha565 3 года назад
@@HeadInstead Oh nice👏👏👏 thanks for replied
@secondsight2091
@secondsight2091 3 года назад
you look like if snowden had a buzzcut and beard
@MrOnizukakira
@MrOnizukakira 8 лет назад
cool
@zes3813
@zes3813 6 лет назад
wrg, xcomputer ts not say or expresx or temptx or interacx. xhuman is, say/expresx/can say expresx anyx nmw and it can all b perfx
@MillionaireTrader
@MillionaireTrader 3 года назад
Me learning python in 2021
@cultofsogga5863
@cultofsogga5863 5 лет назад
Evil :)
@jecssonvillero1546
@jecssonvillero1546 8 лет назад
l
@ahmedamine9853
@ahmedamine9853 3 года назад
bad explanation.
Далее
Exec - Python programming tutorial
5:06
Просмотров 39 тыс.
Be Careful When Using exec() or eval() in Python
9:17
Я нашел кто меня пранкует!
00:51
Как выходим с тройняшками 🙃
00:17
Nice hiding.
00:43
Просмотров 2,8 млн
Python 3 eval() built-in function TUTORIAL
3:52
Просмотров 16 тыс.
Python eval() - Evaluate Expressions Dynamically
14:02
Python Logging - Tutorial
15:02
Просмотров 151 тыс.
Python 3 Programming Tutorial - Subprocess module
13:17
10 Common Python Beginner Mistakes
4:35
Просмотров 209
Я нашел кто меня пранкует!
00:51