1

I have a .py file and I want to make it so I can type it's name in another .py file and have it run all the code from the first file.

Remember, this is in Python 2.7 on a Raspberry Pi 3.

Thank you!

Owen Strand
  • 77
  • 1
  • 1
  • 6

2 Answers2

2

Well you can use execfile() or os.system() to solve your problem. But I think, the correct way to tackle your problem is to import the file in your current script and call the imported file's functions or main function directly from your script.

1

Calling os.system("second.py") or using subprocess.Popen from you first script should work for you.

haronaut
  • 409
  • 3
  • 16