小编sfi*_*ens的帖子

Python abc.abstractproperty兼容性

Python 3文档提到从3.3开始不推荐使用abc.abstractproperty,而赞成@property@abstractmethod。是否有另一种方法来实现abc.abstractproperty与Python 2和3兼容的抽象属性(不带)?

我试过了

import abc
from future.utils import with_metaclass

class Base(with_metaclass(abc.ABCMeta, object)):
    @property
    @abc.abstractmethod
    def x(self):
        raise NotImplementedError

class C(Base):
    pass

C()
Run Code Online (Sandbox Code Playgroud)

TypeError: Can't instantiate abstract class C with abstract methods x在Python 3中正确引发,但在Python 2中不正确。

python abc python-2.7 python-3.x

5
推荐指数
1
解决办法
301
查看次数

netCDF4变量的压缩级别

您如何确定netCDF4变量的压缩级别(最好在Python中)?

python netcdf netcdf4

3
推荐指数
1
解决办法
689
查看次数

标签 统计

python ×2

abc ×1

netcdf ×1

netcdf4 ×1

python-2.7 ×1

python-3.x ×1