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: 
You should not be doing this. Instead, do:

test1.py:

```
 def print_test():
      print "I am a test"
      print "see! I do nothing productive."

```

service.py

```
#near the top
from test1 import print_test
#lots of stuff here
print_test()

```
An example to do it using subprocess.

`from subprocess import run`

`import sys` 

`run([sys.executable, 'fullpathofyourfile.py'])`