Hey! I’d recommend avoiding `exec()` unless you absolutely need it. It’s kinda risky and can lead to security issues if you’re not careful.
Instead, try using `import` to run a Python file from another Python function. For example:
```python
import your_script
your_script.main()
```
This assumes your script has a `main()` function. It’s cleaner and safer than `exec()`.
If you’re dealing with dynamic file paths, `importlib` is your friend. Here’s a quick example:
```python
import importlib.util
spec = importlib.util.spec_from_file_location("module_name", "path/to/your_script.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
module.main()
```
Hope that helps!
Instead, try using `import` to run a Python file from another Python function. For example:
```python
import your_script
your_script.main()
```
This assumes your script has a `main()` function. It’s cleaner and safer than `exec()`.
If you’re dealing with dynamic file paths, `importlib` is your friend. Here’s a quick example:
```python
import importlib.util
spec = importlib.util.spec_from_file_location("module_name", "path/to/your_script.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
module.main()
```
Hope that helps!
