def exec_file(file, global_variables):
'''Executes the provided script as if it were the original script provided
to python.exe. The functionality is similar to `runpy.run_path`, which was
added in Python 2.7/3.2.
The following values in `global_variables` will be set to the following
values, if they are not already set::
__name__ = '<run_path>'
__file__ = file
__package__ = __name__.rpartition('.')[0] # 2.6 and later
__cached__ = None # 3.2 and later
__loader__ = sys.modules['__main__'].__loader__ # 3.3 and later
The `sys.modules` entry for ``__name__`` will be set to a new module, and
``sys.path[0]`` will be changed to the value of `file` without the filename.
Both values are restored when this function exits.
'''
f = open(file, "rb")
try:
code = f.read().replace(to_bytes('\r\n'), to_bytes('\n')) + to_bytes('\n')
finally:
f.close()
exec_code(code, file, global_variables)
visualstudio_py_util.py 文件源码
python
阅读 18
收藏 0
点赞 0
评论 0
评论列表
文章目录