Skip to content

Commit

Permalink
update class G
Browse files Browse the repository at this point in the history
  • Loading branch information
purpleflameangle committed Mar 15, 2019
1 parent 3f6646e commit 6692386
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions venv/pythonlearn/function1.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def delsize(self):


# 描述符property
'''
class MyProperty:
def __get__(self, instance, value):
print("获取属性", self, instance, value)
Expand All @@ -252,13 +253,15 @@ class MyProperty1:
mp.x = 'x-man'
del mp.x
'''


class MyProperty2:
def __init__(self, getx=none, setx=none, delx1=none):

def __init__(self, getx=None, setx=None, fdelx1=None):
self.getx = getx
self.setx = setx
self.delx1 = delx1
self.fdelx1 = fdelx1 # abc

def __get__(self, instance, owner):
return self.getx(instance)
Expand All @@ -267,24 +270,44 @@ def __set__(self, instance, value):
self.setx(instance, value)

def __delete__(self, instance):
self.delx1(instance)
self.fdelx1(instance)


class G:
def __init__(self):
self._gx = gx
self._gx = None

def __get__(self):
def getx(self): # abc
return self._gx

def __set__(self, value):
self._gx =value
def setx(self, value):
self._gx = value

def __delete__(self, instance):
def delx(self):
del self._gx
# print("df")

x = MyProperty2(getx, setx, delx)

gx = MyProperty2(getx, setx, delx1)

g = G()
print(g)
print(g.sx('df'))
# print(g.x('df'))


class CountList:
def __init__(self, *args):
self.value = [i for i in args]
self.count = {}.fromkeys(range(len(self.value)), 0)

def len(self):
return len(self.value)

def fs(self, key):
self.count[key] += 1
return self.value[key]


cl = CountList(1, 2, 3, 4)
print(cl.value)
print(cl.count)

0 comments on commit 6692386

Please sign in to comment.