Do

read it below

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Date : 2018-07-18 10:21:16
# @Author : Simon (simon.xie@codewalker.meg)
# @Link : http://www.codewalker.me
# @Version : 1.0.0

class Desc(object):
def __init__(self, data):
print(f'in init, data is: {data}')
self.data = data
def __get__(self, instance, owner):
print('in get func')
return self.data
def __set__(self, instance, value):
print(f'in set, value is {value}')
self.value = value
class E(object):
x = Desc(10)
def __init__(self, data):
self.x = data
e = E(5)
print(e.x)

Try to comment func __set__, then think about what&why the result are different.

Get

It’s become a non-data descriptor when func __set__ is commented.