time函数

剑指Offer---面试题1---赋值运算符函数

南笙酒味 提交于 2019-12-04 15:15:59
目录 1、赋值运算符函数介绍 2、题解 3、疑问 3.1 常量引用参数 3.2 在VS中调用strcpy()函数 3.3 c++的null和nullptr 剑指Offer-面试题1 给如下类型添加赋值运算符函数。 class CMyString { private: char* m_pData; public: CMyString(const char* pData = nullptr); CMyString(const CMyString& str); ~CMyString(); }; 1、赋值运算符函数介绍 运算符重载是C++一种形式的多态,允许赋予C++运算符多种含义。 例如我们有一个Time类,包括小时和分钟,平常我们是没法直接让两个Time类相加获取总的小时分钟的。这是我们可以使用对+运算符重载。 未使用重载形式的写法 MyTime.h 头文件 #ifndef MYTIME_H_ #define MYTIME_H_ class Time { private: int hour; int minute; public: Time(); Time(int h,int m); //和另一个类时间相加 Time Sum(const Time& t) const; //输出当前类表示的时间 void Show(); }; #endif // !MYTIME_H_ MyTime

闭包函数 装饰器

試著忘記壹切 提交于 2019-12-04 13:33:25
闭包函数 什么是闭包函数: ​ 闭包函数是 函数嵌套、函数对象、名称空间与作用域 结合体 闭包函数注意事项: 闭包函数必须在函数内部定义 闭包函数可以引用外层函数的名字 #直接传参 def func(x): print(x) func(1000) 1000 #通过闭函数传参 def outer(number): def inner(): print(number) return inner func = outer(1000) # --->inner地址 ----> func变量名 func() #---> inner地址 装饰器 什么是装饰器 : 在函数中用来给添加新功能的工具 ​ 为什么要用装饰器: 为了提高代码的可读性,防止代码的冗余 怎么用装饰器: 不修改被装饰对象的源代码 不修改被装饰对象的调用方式 被装饰对象: -----> 需要添加功能 函数 装饰器:------> 被装饰对象添加的新功能 的 函数 time_record --- > 装饰器 # 统计下载电影函数的运行时间 import time def download_movie(): print('电影开始下载...') time.sleep(3) print('电影下载完成...') start_time = time.time() download_movie() end_time = time.time(

python day 6 time 库

醉酒当歌 提交于 2019-12-04 12:19:58
Python day 6 time 库 最基本的处理时间的标准库, (1) 可用于计算机时间的表达 (2) 获取系统时间,格式化输出时间 (3) 精确计时功能,可用于程序性能分析 三类函数 (1) 时间获取: time() ctime() gmtime() (2) 时间格式化: strftime() strptime() (3) 程序计时 sleep() perf_counter() 时间获取 (1) 都是无参数的 (2) Time() 获取当前的时间戳,是一个很长的浮点数, 1573730037.1486392 (3) Ctime() 获得一个易理解的字符串时间 “ 星期 - 月份 - 日期 - 时分秒 - 年份 ” 'Thu Nov 14 19:15:18 2019' (4) Gmtime() 生成一种计算机能够处理的时间格式 time.struct_time(tm_year=2019, tm_mon=11, tm_mday=14, tm_hour=11, tm_min=17, tm_sec=6, tm_wday=3, tm_yday=318, tm_isdst=0) 时间输出格式化 (1) 类似字符串输出格式化,需要有展示模板,展示模板由特定的格式化控制符组成 (2) Strftime(tpl,ts) 方法 tpl 是字符串,是下文提到的时间控制符 ts

Linux内核定时器

≡放荡痞女 提交于 2019-12-04 12:00:40
1、前言 Linux内核中的定时器是一个很常用的功能,某些需要周期性处理的工作都需要用到定时器。在Linux内核中,使用定时器功能比较简单,需要提供定时器的超时时间和超时后需要执行的处理函数。 2、API接口 在Linux内核中使用全局变量jiffies来记录系统从启动以来的系统节拍数,当系统内核启动的时候,会将该jiffies初始化为0,该定义在文件kernel/include/linux/jiffies.h文件中,如下: extern u64 __jiffy_data jiffies_64; extern unsigned long volatile __jiffy_data jiffies; #if (BITS_PER_LONG < 64) u64 get_jiffies_64(void); #else static inline u64 get_jiffies_64(void) { return (u64)jiffies; } #endif 在上面的代码中,jiffies_64与jiffies变量类似,jiffies_64用于64的系统,而jiffies用于32位系统,Linux内核使用HZ表示每秒的节拍数,使用jiffies/HZ可以获得系统已经运行的时间,单位为秒。 /* time_is_before_jiffies(a) return true if a is

1006 Sign In and Sign Out (25 分)

本秂侑毒 提交于 2019-12-04 11:37:58
At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you are supposed to find the ones who have unlocked and locked the door on that day. Input Specification: Each input file contains one test case. Each case contains the records for one day. The case starts with a positive integer M, which is the total number of records, followed by M lines, each in the format: ID_number Sign_in_time Sign_out_time where times are given in the format HH:MM:SS , and ID

函数之闭包函数和装饰器

。_饼干妹妹 提交于 2019-12-04 06:48:06
闭包函数和装饰器 一、闭包函数 1.什么是闭包函数? 字面意思:闭:封闭,包:包裹;闭包函数就是函数嵌套,函数对象,名称空间与作用域的结合体 闭包函数必须在函数内部定义 闭包函数可以引用外层函数的名字 2.闭包函数怎么用 闭包函数是为了装饰器做准备 def outer(num2): num2 = 100 def inner(): # inner就是闭包函数 print(num2) # 如果局部找不到变量名,再从全局找 return inner # 返回inner​func = outer("num2") # 本质是将inner函数名(函数地址)赋值给funcfunc() # 调用inner函数 举例:# 直接传值​import requests​​# 调用爬虫包def spider_func(url): response = requests.get(url) # 接受网址的返回值 if response.status_code == 200: # 判断http的状态码是不是200 print(len(response.text)) # print(response.text)​​url = 'https://www.taobao.com/'spider_func(url)​# 通过闭包函数传值​import requests​​def spider_outer(url): def

闭包函数+装饰器

混江龙づ霸主 提交于 2019-12-04 06:47:00
目录 闭包函数 装饰器: 闭包函数 1.闭包函数必须在函数内部定义 2.闭包函数可以引用外层函数的名字 闭包函数是 函数嵌套、函数对象、名称空间与作用域 结合体。 直接调用 # def func(x): # print(x) # func(1010) 通过闭包函数传参 # def outer(number): # print(number) # def inner(): # print(number) # return inner # # func = outer(100) # func() 直接传入地址,爬取小哥哥的博客 # import requests # def spider_func(url): # response = requests.get(url) # if response.status_code == 200: # print(len(response.text)) # print(response.text) # url = 'https://www.cnblogs.com/zhulipeng-1998/' # spider_func(url) 通过闭包传入地址,爬取小哥哥博客 # import time # import requests # def spider_outer(url): # def spider_inner(): # start_time

闭包函数和装饰器

蹲街弑〆低调 提交于 2019-12-04 06:46:57
闭包函数和装饰器 一-什么是闭包函数? 闭:封闭 ​ 包:包裹 ​ 比如手机的举例 ​ 1.闭包函数必须在函数内部定义 ​ 2.闭包函数可以引用外层函数的名字 ​ -闭包函数是:函数的嵌套、函数的对象、名称空间和作用域 结合体。 ​ ****闭合函数是为了装饰器做准备 def func(y): x = 100 #inner 是一个闭包函数 def inner(): print(x) print(y) return inner inner = func(1) inner() >>>>>> 100 1 二、装饰器 ​ -什么是装饰器? ​ 装饰:装饰 ,修饰。 ​ 器:工具 ​ ********开放封闭***** 装饰器必须遵循“开放封闭“的原则 ​ -开放: ​ 对函数的功能添加是开放的; ​ -封闭: ​ 对函数的功能修改是封闭的。 ​ -装饰器的作用? ​ -在不修改被装饰对象的源代码和调用方式前提下,添加新的功能。 ​ ##装饰器的定义必须遵顼: ​ -不修改被装饰对象的源代码 ​ -不修改被装饰对象的调用方式 ​ -为什么要使用装饰器? ​ 可以解决代码冗余问题,提高代码的可扩展性 ​ -怎么使用装饰器? ​ -装饰器的应用: ​ -登录时间 ​ -登录认证 ​ -编写装饰器 ​ 通过闭包函数来实现装饰器 #爬虫的获取技术 import requests # 爬虫请求工具

python强制结束线程的那点事

故事扮演 提交于 2019-12-04 06:28:41
  在使用python3下载图片时, 常用的方法有urlretrieve和requests两种, 不管哪种方法在网速极慢的情况下, 会出现图片下载卡住现象。那如何解决呢? 小编根据网上提供的资料测试了几种方法。 1、socket: 设置默认超时   正常下载的情况 #!/usr/bin/env python3 # -*- coding:utf-8 -*- # __author__:kzg import datetime import os from urllib.request import urlretrieve # 函数运行计时器 def count_time(func): def int_time(*args, **kwargs): start_time = datetime.datetime.now() # 程序开始时间 func(*args, **kwargs) over_time = datetime.datetime.now() # 程序结束时间 total_time = (over_time-start_time).total_seconds() print("download picture used time %s seconds" % total_time) return int_time # 下载回调函数, 计算下载进度 def callbackinfo

Python的time模块随笔。

混江龙づ霸主 提交于 2019-12-04 04:22:24
Python的time与datetime一直没有好好的深入记录过,今天想到了,先把time的一些基本功能记下来。 首先先上time.time与time.ctime: time.time返回从1970年1月1日0:00到现在的过的时间总秒,类型为浮点型。 time.ctime([具体秒速])可以格式化为本地时间,用与秒速的时间切换最方便,短的时间也很方便。(默认按照计算机本地时区,可以添加负数,时间将减去) In [139]: time.time() Out[139]: 1573369380.742141 In [140]: time.ctime(-20000) Out[140]: 'Thu Jan 1 02:26:40 1970' In [141]: time.ctime(20000) Out[141]: 'Thu Jan 1 13:33:20 1970' In [142]: time.ctime(-2220000) Out[142]: 'Sat Dec 6 15:20:00 1969' In [143]: time.ctime(0) Out[143]: 'Thu Jan 1 08:00:00 1970' time.monotonic用来计算相对时间,因为time.time读取的是计算机时间,如果计算机时间调整的化,会对相对时间差发生变化,该函数可以避免发生。 从时间精度来看