8 examples of 'python exec' in Python

Every line of 'python exec' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
51def _exec_code(self, code):
52 if code:
53 code = compile(code, str(self.filename), 'exec', dont_inherit=True)
54 exec(code, vars(self.namespace))
1def exec_code(code):
2 print(">>> {0}".format(code))
3 try:
4 exec(code)
5 except Exception as e:
6 print(e.__doc__)
7 print(e)
190def exec_(obj, globals=None, locals=None):
191 """ minimal backport of py3k exec statement. """
192 __tracebackhide__ = True
193 if globals is None:
194 frame = sys._getframe(1)
195 globals = frame.f_globals
196 if locals is None:
197 locals = frame.f_locals
198 elif locals is None:
199 locals = globals
200 exec2(obj, globals, locals)
30def execfile(filename, globals, locals):
31 """Python 3 replacement for ``execfile``."""
32 # Credit: 2to3 and this StackOverflow answer
33 # (http://stackoverflow.com/a/437857/841994) take similar
34 # approaches.
35 with open(filename) as f:
36 code = compile(f.read(), filename, 'exec')
37 exec(code, globals, locals)
7def execfile3(file, globals=globals(), locals=locals()):
8 with open(file, "r") as fh:
9 exec(fh.read()+"\n", globals, locals)
330def r_execfile(self, file):
331 """Execute the Python code in the file in the restricted
332 environment's __main__ module.
333
334 """
335 m = self.add_module('__main__')
336 execfile(file, m.__dict__)
93def s_exec(self, code):
94 """
95 *code* must be a string containing one or more lines of Python code, which will
96 be executed in the restricted environment.
97
98
99 """
100 pass
36def exec_(self, code):
37 try:
38 exec(code, {CLASSNAME: self.sp})
39 except Exception as e:
40 logging.exception(e)

Related snippets