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.
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.
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.
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
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).
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?
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'])
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 :(
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)
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()
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?
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...