#!/usr/bin/env python# -*- coding:utf-8 -*- import time #方式1class People: def __init__(self, name, age): self.__name = name self.__age = age def get_age1(self): return self.__age def set_age2(self, age): if isinstance(age, int): self.__age = age else: raise ValueError def del_age3(self): print("删除年龄数据!") # 核心在这句 age1 = property(get_age1, set_age2, del_age3, "年龄") obj = People("jack", 18)print(obj.age1)obj.age = 19print("obj.age: ", obj.age)del obj.age #方式2def deco(f): def wrapper(): start_time = time.time() f() end_time = time.time() execution_time = (end_time - start_time)*1000 print("time is %d ms" %execution_time ) return wrapper @decodef f(): print("hello") time.sleep(1) print("world") if __name__ == ‘__main__‘: f()
原文地址:https://www.cnblogs.com/NiceTime/p/10085350.html
时间: 2024-10-10 22:30:17