io.py 文件源码

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

项目:ommprotocol 作者: insilichem 项目源码 文件源码
def _pickle_load(path):
        """
        Loads pickled topology. Careful with Python versions though!
        """
        _, ext = os.path.splitext(path)
        topology = None
        if sys.version_info.major == 2:
            if ext == '.pickle2':
                with open(path, 'rb') as f:
                    topology = pickle.load(f)
            elif ext in ('.pickle3', '.pickle'):
                with open(path, 'rb') as f:
                    topology = pickle.load(f, protocol=3)
        elif sys.version_info.major == 3:
            if ext == '.pickle2':
                with open(path, 'rb') as f:
                    topology = pickle.load(f)
            elif ext in ('.pickle3', '.pickle'):
                with open(path, 'rb') as f:
                    topology = pickle.load(f)
        if topology is None:
            raise ValueError('File {} is not compatible with this version'.format(path))
        return topology
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号