Câu hỏi được gắn thẻ «python-descriptors»

2
Tại sao việc đặt một bộ mô tả trên một lớp ghi đè lên bộ mô tả?
Repro đơn giản: class VocalDescriptor(object): def __get__(self, obj, objtype): print('__get__, obj={}, objtype={}'.format(obj, objtype)) def __set__(self, obj, val): print('__set__') class B(object): v = VocalDescriptor() B.v # prints "__get__, obj=None, objtype=<class '__main__.B'>" B.v = 3 # does not print "__set__", evidently does not trigger descriptor B.v # does not print anything, we …
Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.