Question: I have a script named `test1.py` which is not in a module. It just has code that should execute when the script itself is run. There are no functions, classes, methods, etc. I have another script which runs as a service. I want to call `test1.py` from the script running as a service.

For example:

File **`test1.py`**:

```
print "I am a test"
print "see! I do nothing productive."

```

File **`service.py`**:

```
# Lots of stuff here
test1.py # do whatever is in test1.py

```

I'm aware of one method which is opening the file, reading the contents, and basically evaluating it. I'm assuming there's a better way of doing this. Or at least I hope so.

Answer: 
As it's already mentioned, `runpy` is a nice way to run other scripts or modules from current script. 

By the way, it's quite common for a tracer or debugger to do this, and under such circumstances methods like importing the file directly or running the file in a subprocess usually do not work.

It also needs attention to use `exec` to run the code. You have to provide proper `run_globals` to avoid import error or some other issues. Refer to `runpy._run_code` for details.
This is an example with `subprocess` library:

```
import subprocess

python_version = '3'
path_to_run = './'
py_name = '__main__.py'

# args = [f"python{python_version}", f"{path_to_run}{py_name}"]  # works in python3
args = ["python{}".format(python_version), "{}{}".format(path_to_run, py_name)]

res = subprocess.Popen(args, stdout=subprocess.PIPE)
output, error_ = res.communicate()

if not error_:
    print(output)
else:
    print(error_)

```