python中property(lambda self: object())简单解释

Posted skyone1

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python中property(lambda self: object())简单解释相关的知识,希望对你有一定的参考价值。

最后4行lambda。问题是:如何运作?它们的含义和结果是什么?您能否以简单的方式显示该声明的示例?现在谢谢!

class error(Exception):
    """ Base class for I/O related errors. """
    def __init__(self, *args, **kwargs): # real signature unknown
        pass

    @staticmethod # known case of __new__
    def __new__(S, *more): # real signature unknown; restored from __doc__
        """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
        pass

    def __reduce__(self, *args, **kwargs): # real signature unknown
        pass

    def __str__(self): # real signature unknown; restored from __doc__
        """ x.__str__() <==> str(x) """
        pass

    characters_written = property(lambda self: object()) # default
    errno = property(lambda self: object()) # default
    filename = property(lambda self: object()) # default
    strerror = property(lambda self: object()) # default

1个

property是内置的。通常用作装饰器。该代码与此等效,可能看起来更加熟悉:

class error(Exception):
    #...
    @property
    def characters_written(self):
        return object()

    @property
    def errno(self):
        return object()

    @property
    def filename(self):
        return object()

    @property
    def strerror(self):
        return object()

以上是关于python中property(lambda self: object())简单解释的主要内容,如果未能解决你的问题,请参考以下文章

python之property类方法和静态方法

Python的黑魔法@property装饰器的使用技巧

JAVA SE面向对象编程之Lambda

Java SE8 之 Lambda 表达式详解

Java SE8 之 Lambda 表达式详解

Java SE 8 for the Really Impatient读书笔记——Java 8 Lambda表达式