小编Ama*_*mal的帖子

Python静态类属性set/get

可能重复:
python中的私有函数/变量实现

可以使用两个静态属性创建与以下类的等效项,一个是只读的,另一个是Python中的读写?

class Foo
{
    private static string _rdy = "RO";
    public static string rd
    {
        get { return _rd; }
    }

    private static string _rw = "RW";
    public static string rw
    {
        get { return _rw ; }
        set { _rw = value; }
    }
}
Run Code Online (Sandbox Code Playgroud)

我知道在Python中可以使用只读类属性,但我怎么没有在Python中看到任何读写类属性的例子.可能吗?基本上我想要:

class classproperty(object):

    def __init__(self, getter
            #, setter
        ):
        self.getter = getter
    #    self.setter = setter

    def __get__(self, instance, owner):
        return self.getter(owner)

    # Could there be a __set__ here?
    #vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv …
Run Code Online (Sandbox Code Playgroud)

python properties class

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

class ×1

properties ×1

python ×1