🌐
Programiz
programiz.com › python-programming › methods › built-in › exec
Python exec() (With Examples)
The exec() method executes the dynamically created program, which is either a string or a code object. In this tutorial, you will learn about the exec() method with the help of examples.
🌐
W3Schools
w3schools.com › python › ref_func_exec.asp
Python exec() Function
The exec() function executes the specified Python code. The exec() function accepts large blocks of code, unlike the eval() function which only accepts a single expression ... If you want to use W3Schools services as an educational institution, ...
🌐
O'Reilly
oreilly.com › library › view › python-essential-reference › 0672328623 › 0672328623_ch06lev1sec13.html
Python: Essential Reference, Third Edition
February 20, 2006 - The code supplied to exec is executed as if the code actually appeared in place of the exec statement. For example: ... Finally, the execfile(filename [,globals [,locals]]) function executes the contents of a file.
Author   David Beazley
Published   2006
Pages   648
🌐
Python Programming
pythonprogramming.net › python-exec-tutorial
Exec with Python Tutorial
This is another example of something people might get the wild idea of using unprotected with some sort online form so they can create their own embedded Python IDE in a browser. Let's see some examples of exec. If you recall from the previous tutorial, eval wouldn't compile any code.
🌐
GeeksforGeeks
geeksforgeeks.org › exec-in-python
exec() in Python - GeeksforGeeks
November 29, 2023 - Dynamic execution in Python allows the execution of specific methods such as sum() and iter() along with built-in methods inside the exec() function, demonstrating the flexibility of dynamic execution in Python.
🌐
DataFlair
data-flair.training › blogs › python-exec-function
Python exec Function - Example and Risk - DataFlair
November 24, 2018 - Learn what the exec function is in Python with syntax and example, Exec vs eval, Risks with Python Exec - problem & Solution
🌐
Delft Stack
delftstack.com › home › howto › python › execfile in python 3
How to Execute a Script in Python | Delft Stack
February 2, 2024 - The above code first opens a file in the working directory by the name of code.py, reads its content, stores it inside a variable by the name content, and then passes the read content to the exec() function.
Find elsewhere
🌐
docs.python.org
docs.python.org › 3 › library › functions.html
Built-in Functions — Python 3.11.5 documentation
The Python interpreter has a number of functions and types built into it that are always available. They are listed here in alphabetical order.,,,, Built-in Functions,,, A, abs(), aiter(), all(), a...
🌐
YouTube
youtube.com › watch
Exec - Python programming tutorial - YouTube
This function supports dynamic execution of Python code. object must be either a string or a code object. If it is a string, the string is parsed as a suite ...
Published   May 24, 2015
🌐
CodeRivers
coderivers.org › blog › python-execfile
Python `execfile` - A Comprehensive Guide - CodeRivers
February 22, 2026 - In Python, the `execfile` function has been a part of the language's toolset for a long time. It allows you to execute Python code from an external file within your Python script. This can be extremely useful in various scenarios, such as modularizing code, reusing common code snippets across ...
🌐
TutorialsPoint
tutorialspoint.com › exec-in-python
exec() in Python
Exec function can dynamically execute code of python programs. The code can be passed in as string or object code to this function. The object code is executed as is while the string is first parsed and checked for any syntax error. If no syntax e
🌐
Real Python
realpython.com › python-exec
Python's exec(): Execute Dynamically Generated Code – Real Python
November 10, 2022 - The exec() function can be handy when you need to run dynamically generated Python code, but it can be pretty dangerous if you use it carelessly. In this tutorial, you’ll learn not only how to use exec(), but just as importantly, when it’s okay to use this function in your code.
🌐
AskPython
askpython.com › home › understanding the python exec() method
Understanding the Python exec() Method - AskPython
August 6, 2022 - So today in this tutorial, let’s get to know about the Python exec() method in Python.
🌐
Sololearn
sololearn.com › en › Discuss › 553584 › how-do-i-make-a-python-file-executable-from-the-console
How do i make a python file executable from the console? | Sololearn: Learn to code for FREE!
If you save your python file (e.g. "your_file.py") in the same directory as python.exe, you can run it from the console with the command: >>>exec(open("your_file.py").read()) You can also write your file there with (e.g.) >>>newfile = open("your_file.py", "w") >>>newfile.write("print('hello world!')") >>>newfile.close() You can check to make sure it is there with >>>import os >>>os.listdir() You should get something like this: ['DLLs', 'Doc', 'include', 'Lib', 'libs', 'LICENSE.txt', 'NEWS.txt', 'python.exe', 'python3.dll', 'python36.dll', 'pythonw.exe', 'Scripts', 'tcl', 'Tools', 'vcruntime140.dll', 'your_file.py'] This is what you get when you run it: >>>exec(open("your_file.py").read()) hello world! ... The function execfile() doesnt exist in Python 3.
🌐
pkimber.net
pkimber.net › howto › python › execfile.html
execfile — pkimber.net
Python · execfile · View page source · Calling scripts using another script · Use the execfile command to call a script from another script. Create a script called testFunctions.py that contains the following: def printName(first, last): name = first + ' ' + last return name ·
🌐
Nmt
cs.nmt.edu › ~jeffery › Shipman › www › docs › tcc › help › pubs › python27 › web › execfile-function.html
21.7. execfile(): Execute a Python source file
To execute a sequence of Python statements in some file F, use this function: execfile(F) The function returns None. For additional features that allow you to control the environment of the executed statements, see the official documentation. Next: 21.8. getattr(): Retrieve an attribute of ...
🌐
Readthedocs
casadocs.readthedocs.io › en › stable › api › casashell › execfile.html
execfile — CASAdocs documentation
When execfile is used within the filename being evaluated, it is necessary to add globals( ) as the second argument to those execfile calls in order for the secondary script to know about the global variables of the calling script. For example, within a script ‘mainscript.py’, calls to another script ‘myscript.py’ should be written as execfile(‘myscript.py’, globals()).