visualstudio_py_repl.py 文件源码

python
阅读 37 收藏 0 点赞 0 评论 0

项目:pythonVSCode 作者: DonJayamanne 项目源码 文件源码
def run_file_as_main(self, filename, args):
        f = open(filename, 'rb')
        try:
            contents = f.read().replace(to_bytes('\r\n'), to_bytes('\n'))
        finally:
            f.close()
        sys.argv = [filename]
        sys.argv.extend(_command_line_to_args_list(args))
        self.exec_mod.__file__ = filename
        if sys.platform == 'cli':
            code = python_context.CreateSnippet(contents, None, SourceCodeKind.File)
            code.Execute(self.exec_mod)
        else:
            self.code_flags = 0
            real_file = filename
            if isinstance(filename, unicode) and unicode is not str:
                # http://pytools.codeplex.com/workitem/696
                # We need to encode the unicode filename here, Python 2.x will throw trying
                # to convert it to ASCII instead of the filesystem encoding.
                real_file = filename.encode(sys.getfilesystemencoding())
            code = compile(contents, real_file, 'exec')
            self.code_flags |= (code.co_flags & BasicReplBackend.future_bits)
            exec(code, self.exec_mod.__dict__, self.exec_mod.__dict__)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号