Coverage for src/pyrsslocal/helper/python_run.py: 90%
10 statements
« prev ^ index » next coverage.py v7.1.0, created at 2024-04-23 08:45 +0200
« prev ^ index » next coverage.py v7.1.0, created at 2024-04-23 08:45 +0200
1"""
2@file
3@brief contains functionalities to run a python script
4"""
7def run_python_script(script, params=None):
8 """
9 Executes a script python as a string.
11 @param script python script
12 @param params params to add before the execution
14 .. exref::
15 :title: compile and run a custom script
17 ::
19 fpr = lambda v : self.outStream.write(str(v) + "\n")
20 pars = {"print": fpr, "another_variable": 3 }
21 run_python_script(script, pars)
22 """
23 if params is None:
24 params = {}
25 obj = compile(script, "", "exec")
27 loc = locals()
28 for k, v in params.items():
29 loc[k] = v
30 loc["__dict__"] = params
32 try:
33 exec(obj, globals(), loc)
34 except Exception as e: # pragma: no cover
35 raise e