def _run_script(script_file):
"""Run the script at the provided path
:param str script_file: A path to a python script to run
"""
builtins = __builtins__
import __main__
__main__.__dict__.clear()
__main__.__dict__.update(dict(
__name__ = "__main__",
__file__ = script_file,
__builtins__ = builtins
))
globals = __main__.__dict__
locals = globals
# repr will put the script_file into quotes and escape any
# unruly characters
# NOTE that at this point, sys.argv will already have been reset
# so that it will look like (from script_file's point of view),
# that it was the first file run instead of pipless.
exec 'execfile({})'.format(repr(script_file)) in globals, locals
评论列表
文章目录