Тёмный

Exec - Python programming tutorial 

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

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

 

3 окт 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 46   
@veryblocky
@veryblocky 8 лет назад
Thank you, this really helped me to understand how to use exec, way better than other tutorials!
@sentdex
@sentdex 8 лет назад
+George Willcox great to hear!
@anubhavsharma6263
@anubhavsharma6263 4 года назад
its 2020 and still no options available except sentdex... respect from India..
@cheddacheese148
@cheddacheese148 7 лет назад
Thumbs up for the snip snap. You've earned a new subscriber. I dig the quick vids, simple lessons, and immediate applications. I've been using python for a year now but I'm constantly patching holes in my knowledge of the language. These videos are perfect for that.
@fa33727
@fa33727 8 лет назад
Awesome bro.. but when do we actually want to use it?
@soosl9356
@soosl9356 3 года назад
See, Im making a discord bot. I want to be able to run code from discord, so I can talk to my discord bot, and tell it to run code using exec! Thats one example of a use.
@leonardodavinci1329
@leonardodavinci1329 3 года назад
When you build AGI for example, and want it to program itself.
@mihirkatoch1110
@mihirkatoch1110 4 года назад
Now my love for python has increased!!!!
@Exposingscammers
@Exposingscammers 3 года назад
Thanks heaps. I was stuck trying to find a command to do this and exec is the one (Newby at Python) Thankfully nobody can input stuff for my application.
@АлександрГаланин-щ6и
def func(var, cond, collection): exec(f"""result = list(filter(lambda {var}: {cond}, {collection}))""") return locals()['result'] list_of_ints = [1,2,3,4,6] list_of_strings= ['first', 'last', 'default'] print(func('x', 'x != 6', list_of_ints )) print(func('x', 'x.__contains__("default")', list_of_strings)) Some kind of filter func with different conditions. Of course this is just example, but this is what you can do with exec func
@karanjit28
@karanjit28 9 лет назад
i was wondering could you do some psuedo code examples with questions from past exam questions
@thomascleveland
@thomascleveland 2 года назад
watching this 7 years after the fact reminded me how people used to exclaim 'oh snap'. Kids don't say that anymore
@SelfEnergetic
@SelfEnergetic 3 года назад
Nice tut but what is the end in mind in dealing with a string operation in the first place. could someone be as dummy as me and try to come to the root of different silly things (at least before you realize it is not).
@CoolTomato
@CoolTomato 9 лет назад
Is there a way to use exec to execute a separate file, say hello.py without importing it like if it has same imports as the file you're executing it from?
@sentdex
@sentdex 9 лет назад
CoolTomato33 You'd really just import it. You could use subprocess to execute another file though if you really wanted to, an example would be something like: import subprocess subprocess.call(['python', 'pyfile.py'])
@randomsnow6510
@randomsnow6510 2 года назад
theres a function called compile() that does that
@TheStevenStevenson
@TheStevenStevenson Год назад
2:37 how come the output equals None? Love the videos!
@eltriplej6944
@eltriplej6944 7 лет назад
The REAL question is if you can run exec in exec! Mindblowing.
@samueln300
@samueln300 6 лет назад
*Compassion Is Forgiveness* tried it and you can!!
@caponedbege210
@caponedbege210 5 лет назад
dude ! don't push your luck !
@SarcTiann
@SarcTiann 5 лет назад
Some things don´t work... I´m trying make a simple dinamic python ide :P ...So I use a scrolledtext from tkinter for input a "code" and another for the outputs. then redirect the stdout to catch shell output. I want to know how make a class definition or get an user input :D ...or get the Tracebacks errors... Aparently I need define globlas and locals in the exec, but I don´t figure how for now :(
@hussainshaikh5615
@hussainshaikh5615 7 лет назад
exec("a = lambda x:x*7") print(a(5)) This Works...to....its like Dangerous Crazy
@devinjones3350
@devinjones3350 6 лет назад
but this is not working can u pls help me for that ? my python version 3.6.4 def mn(): exec("lst_str2 = [5,6,7,8,9]") print(lst_str2) mn()
@jojothegreat2130
@jojothegreat2130 6 лет назад
I tried your code. It works. Can you explain the error you are getting?
@devinjones3350
@devinjones3350 6 лет назад
did u use 2.x ? am right?? its working fine on 2.x but its not working on 3.x that is my problem
@oliverlykkeviskum6485
@oliverlykkeviskum6485 6 лет назад
What program do you use for your codes? I am watching one of your other video tutorials but I don't seem to be able to get the screenshot. (Using Anaconda, to run)
@panneerselvammanisekaran2413
@panneerselvammanisekaran2413 8 лет назад
How to do a Exec Global? I mean I want a Dynamically create a global variable. Please help
@abhishekanand3285
@abhishekanand3285 6 лет назад
my str2 not define error is coming
@shreyakrishnam9708
@shreyakrishnam9708 5 лет назад
Could you explain a bit more about the optional parameters globals and locals
@Tormasan
@Tormasan 7 лет назад
i learned a lot so far thank you so much i keep watching i have a big interest in ML and stocks to so this is a very nice place to me
@drakensangoynuyoronline1212
@drakensangoynuyoronline1212 5 лет назад
the best tutorials! thanksThank you, this really helped me to understand how to use exec, way better than other tutorials!
@tarikat6870
@tarikat6870 8 лет назад
mylist = '[5,5,7,8,9,6,5,4,2,3,1]' listr = exec(mylist) print (listr) exec('list2 = mylist') print (list2) exec('''def Mytest(): print('hey it works ') Mytest() ''') exec('''for i in range(6): print(i) i= i+1''')
@jocyyao9818
@jocyyao9818 3 года назад
Hi, when I want to define a class by using exce(), I always failed to create def__init__, and it always showed me I got a syntax error, do u know any possible mistake. BTW I am sure I don't have ann actual syntax error on the string I passed into exce()
@maxsterlingj5842
@maxsterlingj5842 7 лет назад
Thank you
@keshan-spec
@keshan-spec 5 лет назад
"hot digidy" ~sentdext
@RealMcDudu
@RealMcDudu 8 лет назад
great tutorial series - thanks a lot!
@jhonatansiles4455
@jhonatansiles4455 7 лет назад
muchas gracias !
@techbytes4u492
@techbytes4u492 9 лет назад
nice video
@pretzels3273
@pretzels3273 8 лет назад
Why is exec dangerous?
@sentdex
@sentdex 8 лет назад
+CanadianGamer bc you will exec whatever is in there. If you exec user input, they could do malicious things.
@skillato9000
@skillato9000 5 лет назад
Isn't Exec just a better Eval? What stops us from using always the first one? (Love your lessons)
@aikimark1955
@aikimark1955 9 лет назад
I often refer to such language features, Eval/Exec, as macro-enabling. Is there a performance advantage to Exec() compilation over regular Python interpretation? For instance, can Exec() be used to bypass GIL parallel performance limitations?
@darronpressley6855
@darronpressley6855 9 лет назад
Thanks Harrison, think I can use that to add custom code to an app without altering the app itself
@darronpressley6855
@darronpressley6855 9 лет назад
although cant pass into or return from it?
@eirhnhpap18
@eirhnhpap18 8 лет назад
hello, i wrote a code on html-php and i want onclick to run a source code with help of python. Do you know how can i connect this .exe on python? and after that python with php? it's a project in my class and i need help...
Далее
LOLLIPOP-SCHUTZ-GADGET 🍭 DAS BRAUCHST DU!
00:28
Просмотров 2,6 млн
У КОТЯТ ОТКРЫЛИСЬ ГЛАЗКИ#cat
00:26
Лиса🦊 УЖЕ НА ВСЕХ ПЛОЩАДКАХ!
00:24
Python 3 Programming Tutorial - Threading module
18:43
Просмотров 198 тыс.
Python eval() - Evaluate Expressions Dynamically
14:02
Compiled Python is FAST
12:57
Просмотров 111 тыс.
Be Careful When Using exec() or eval() in Python
9:17
Python Decorators in 15 Minutes
15:14
Просмотров 444 тыс.
Dependency Injection, The Best Pattern
13:16
Просмотров 831 тыс.
Just Use Pydantic
8:11
Просмотров 24 тыс.