Skip to content

Instantly share code, notes, and snippets.

@boseji
Created February 24, 2014 04:54
Show Gist options
  • Save boseji/9182144 to your computer and use it in GitHub Desktop.
Save boseji/9182144 to your computer and use it in GitHub Desktop.
Runner function for executing Python scripts from inside a Python script
import os,sys,importlib
from os import path
def Runner(sRootPath):
''' Runs all the scripts in lower directories
@param sRootPath Specifies the Path from which Script Running should start
@return None
'''
try:
for root, dirs, files in os.walk(sRootPath):
#bypass dir with _ and __ , Process only if some files
if (root.endswith('_') == False) and (len(files) > 0 ) and \
(root != sRootPath) and (root.find("__")==-1):
print("-" * 20)
print(" Root: ",root)
print("-" * 20)
for name in files:
#check for scripts but avoid packages
if name.endswith(".py") and (root.find("__")==-1):
print(" Running Script : ",name)
#RunScript(root,name)
print()
except Exception as p:
print("\nProblem in Runner :",p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment