《Python
来源:互联网 发布:小非农数据公布网站 编辑:程序博客网 时间:2024/06/12 10:45
主要结合程序认识理解Python中的装饰器。练习Python代码的编写。
简单代码
#!/usr/bin/env python#-*- coding: utf-8 -*-"""@author: 烽火@license: Apache Licence @file: decorate.py@time: 7/5/17 3:52 PM"""import time"""定义简单的装饰器,用来输出程序运行的所用时间"""def timer(func): def decor(*args): start_time = time.time(); func(*args); end_time = time.time(); d_time = end_time - start_time print("run the func use : ", d_time) return decor;@timer #printSth = timer(printSth) -> printSth = decordef printSth(str, count): for i in range(count): print("%d hello,%s!"%(i,str))printSth("world", 100)
运行结果
阅读全文
0 0
- Python
- Python
- Python
- python
- Python
- PYTHON
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- python
- Python
- 博客地址
- 自定义注解
- arm-linx-参数
- linux 6 网卡名称修改
- 播放器的基本原理(播放四步法)
- 《Python
- 用两个栈实现队列
- 安卓Android开发笔记——textview 中划线,下划线
- 【R的机器学习】模型性能提升探索:R的其他神经网络包-neuralnet
- 使数据库中的<html>标签可以显示在前端
- 关于spring下自定义异常处理的功能
- Cookie/Session机制
- java-构造方法
- 心得 : 面向对象和面向过程的区别