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()
相关推荐
meylovezn 2020-09-21
mmmjyjy 2020-07-16
typhoonpython 2020-06-11
x青年欢乐多 2020-06-06
Stranger 2020-05-16
QianYanDai 2020-04-18
千锋 2020-04-11
SDUTACM 2020-03-05
fly00love 2020-03-05
f = lambda x, y, z: x + y + z # returns a function that can optionally be assigned a name. def func:
sschencn 2020-02-21
wklken的笔记 2020-01-30
GhostLWB 2020-01-30
sulindong0 2020-01-19
chinademon 2020-01-12
mieleizhi0 2020-01-11
samsai00 2020-01-06