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: 
This is possible in Python 2 using

```
execfile("test2.py")

```

See the [documentation](https://docs.python.org/2/library/functions.html#execfile) for the handling of namespaces, if important in your case.

In Python 3, this is possible using (thanks to @fantastory)

```
exec(open("test2.py").read())

```

However, you should consider using a different approach; your idea (from what I can see) doesn't look very clean.
I prefer [runpy](https://docs.python.org/3/library/runpy.html):

```
#!/usr/bin/env python
# coding: utf-8

import runpy

runpy.run_path(path_name='script-01.py')
runpy.run_path(path_name='script-02.py')
runpy.run_path(path_name='script-03.py')

```