configuration.py 文件源码

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

项目:choronzon 作者: CENSUS 项目源码 文件源码
def make_module_from_file(self, module_name, module_filepath):
        """
            Make a new module object from the source code in specified file.

            :param module_name: The name of the resulting module object.
            :param module_filepath: The filesystem path to open for
                reading the module's Python source.
            :return: The module object.

            The Python import mechanism is not used. No cached bytecode
            file is created, and no entry is placed in `sys.modules`.

        """
        py_source_open_mode = 'U'
        py_source_description = (".py", py_source_open_mode, imp.PY_SOURCE)

        with open(module_filepath, py_source_open_mode) as module_file:
            with self.preserve_value(sys, 'dont_write_bytecode'):
                sys.dont_write_bytecode = True
                module = imp.load_module(
                        module_name, module_file, module_filepath,
                        py_source_description)

        return module
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号