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()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM