0基础学Pythone(5)——描述符相关的魔术方法
来源:互联网 发布:wordpress cms 主题 编辑:程序博客网 时间:2024/05/04 06:50
声明一个人类: 使用描述符管理用户的身份证号:
获取身份证号 隐藏出生年日
设置身份证号 18位数而且年月日必须符合规则
删除身份证号 此人死亡允许删除,不死亡禁止删除
class Human:
name = '***'
def __init__(self):
self.sfzh = '101010199909090909'
def __get__(self,obj,cls):
res = str(self.sfzh[:6]) + '******' + str(self.sfzh[-4:])
return res
def __set__(self,obj,value):
mouth = value[11:12]
day = value[13:14]
if 1 <= int(mouth) <= 12 and 1 <= int(day) <= 31:
self.sfzh = value
else:
print('NoNoNo')
def __delete__(self, obj):
if obj.live:
pass
else:
del self.sfzh
class Hhh:
ren = Human()
live = True #True就是活着
h = Hhh()
#print(h.ren)
h.ren = '111111199811111111'
print(h.ren)
#del h.ren
#print(h.ren)
获取身份证号 隐藏出生年日
设置身份证号 18位数而且年月日必须符合规则
删除身份证号 此人死亡允许删除,不死亡禁止删除
class Human:
name = '***'
def __init__(self):
self.sfzh = '101010199909090909'
def __get__(self,obj,cls):
res = str(self.sfzh[:6]) + '******' + str(self.sfzh[-4:])
return res
def __set__(self,obj,value):
mouth = value[11:12]
day = value[13:14]
if 1 <= int(mouth) <= 12 and 1 <= int(day) <= 31:
self.sfzh = value
else:
print('NoNoNo')
def __delete__(self, obj):
if obj.live:
pass
else:
del self.sfzh
class Hhh:
ren = Human()
live = True #True就是活着
h = Hhh()
#print(h.ren)
h.ren = '111111199811111111'
print(h.ren)
#del h.ren
#print(h.ren)
阅读全文
0 0
- 0基础学Pythone(5)——描述符相关的魔术方法
- 学Python(5)—魔术方法
- Pythone面向对象方法
- PHP的超全局变量以及相关魔术方法
- Flex的魔术方法 — flash.utils.flash_proxy
- task—struct的相关描述
- php基础之魔术方法
- php面向对象基础概念(属性重载的魔术方法)__get(),__set(),__isset(),__unset()
- php魔术方法的使用(总结)
- php的魔术方法
- php的魔术方法
- php的魔术方法
- PHP的魔术方法
- PHP的魔术方法
- PHP的魔术方法
- python的魔术方法
- php的魔术方法
- php的魔术方法
- socket-服务器端-01
- DOM2级事件绑定的兼容处理
- Linux内核基础--事件通知链(notifier chain)
- Spring Boot报错:This application has no explicit mapping for /error......
- 阿里巴巴,工程师面试经历,荆棘密布
- 0基础学Pythone(5)——描述符相关的魔术方法
- 使用gsl求解多参数方程方法实例
- 史上最简单的SpringCloud教程 | 第八篇: 消息总线(Spring Cloud Bus)
- 闭包的应用二 -----(局部变量的累加)
- 软件合集
- 中国IT行业的风投大家--阎焱
- Android的Drawable
- 关于使用springmvc时Failed to load resource: the server responded with a status of 400 (Bad Request)错误可能原因
- 启动活动---传递参数的最佳写法