ctime

python模组--调用模块(虫师《selenium3自动化测试实战--基于Python语言笔记5》)

自作多情 提交于 2019-11-28 18:15:36
1.调用time模块的ctime()方法 # 调用 time 模块 # 方法1 import time print(time.ctime()) # ctime()获得当前时间:Tue Aug 27 15:22:53 2019 #方法2 from time import ctime print(ctime()) 2.导入多个函数 # 导入多函数 from time import time, sleep # 导入全部函数 from time import * 3.给导入函数重命名 # 导入函数重命名as from time import sleep as sys_sleep 4.查看time模块的所有函数 >>> import time >>> help(time) time() 以秒为单位将当前时间作为浮点型返回(1970.1.1至当前时间的秒数) e.g:1566892931.970801 clock() 返回进程以浮点型启动后的CPU时间 e.g:5.688890507062189e-07 sleep() 以浮点型给出的延迟数秒 e.g:time.sleep(2):延迟2s gmtime() 将epoch以来的秒数转换为UTC元组(epoch=1970.1.1) e.g:time.struct_time(tm_year=2019, tm_mon=8, tm_mday=27, tm

Web微信之用户扫码

自作多情 提交于 2019-11-28 10:12:10
v=re.findall(' uuid="(.*)");',response.text) v是(.*)分组的内容,一个列表 from django.shortcuts import render,HttpResponse import requests import time import re import json CTIME = None QCODE = None TIP = 1 ticket_dict ={} def login(request): global CTIME CTIME = time.time() response = requests.get( url ='https://login.wx.qq.com/jslogin?appid=wx782c26e4c19acffb&fun=new&lang=zh_CN&_=%s' % CTIME ) v = re.findall('uuid = "(.*)";',response.text) global QCODE QCODE = v[0] return render(request,'login.html',{'qcode':QCODE}) def check_login(request): global TIP ret = {'code': 408,'data': None} r1 = requests.get(

Linux下who命令之C语言实现

♀尐吖头ヾ 提交于 2019-11-28 09:20:34
Linux下who命令之C语言实现 Step1:前期准备 首先要有一个清楚的认识:linux中一切皆文件 实现who命令,who命令也是Linux中的一个文件,那我们怎么找到它呢?我们可以“找男人”(man),终端下执行命令: man who 此处我装了汉译版的man手册,查看到这样一段提示如下: 所以退出man手册,执行命令: info who 找到如下图相关信息: 也可以找到下面这样的一段话,也就是说: who命令可以这样实现,读取utmp里边的内容,然后显示记录,最后关闭utmp,who命令就是一个很简单的体现吧,打开文件,保存文件id,根据文件id读取用户的登陆信息,显示在终端。 我们尝试地打开一下 /var/run/utmp 这个文件得到如下画面,发现是一串乱码,但还是能看出相关who的信息的 既然不清楚 utmp 是干嘛的,我们可以使用 man -k 来检索一下相关信息,得到信息如下 经过筛选,发现只有 utmpx(5) 是符合我们要求的,其中后面显示的是 login records ,而who命令不就是用来输出登录信息的; man 的第五个类型表示的是 文件格式和规范 ,说明此处可能存储了登录记录的数据结构 使用指令: man 5 utmpx ,可以得到如下有用信息: 也可以使用输出重定向指令 man 5 utmpx > utmp.txt ,得到文本格式的 utmp

Python连载32-多线程其他属性以及继承Thread类

余生长醉 提交于 2019-11-28 06:36:55
一、线程常用属性 1.threading.currentThread:返回当前线程变量 2.threading.enumerate:返回一个包含正在运行的线程的list,正在运行的线程指的是线程启动后,结束前的状态 3.threading.activeCount:返回正在运行的线程数量,效果跟len(threading.enumer)一样 4.thr.setName:给线程设置名字 5.thr.getName:得到线程的名字。 举例: i mport _thread as thread import time def loop1(in1): print("Start loop 1 at:",time.ctime()) print("我是参数",in1) time.sleep(4) print("End loop 1 at:",time.ctime()) ​ def loop2(in1,in2): print("Start loop 2 at:",time.ctime()) print("我是参数",in1,"和参数 ",in2) time.sleep(4) print("End loop 2 at:",time.ctime()) ​ import threading def main1(): print("Starting at:",time.ctime()) t1 =

C++ - 'localtime' this function or variable may be unsafe

主宰稳场 提交于 2019-11-28 04:54:51
问题 I am writing a simple logging class in C++ for learning purposes. My code contains a function that returns a string of today's date. However, I get a compiler error whenever 'localtime' is called. std::string get_date_string(time_t *time) { struct tm *now = localtime(time); std::string date = std::to_string(now->tm_mday) + std::to_string(now->tm_mon) + std::to_string(now->tm_year); return date; } I have tried using #define _CRT_SECURE_NO_WARNINGS . It didn't work and the same error appeared.

初试linux,cp、rm、mv、file、umask等命令粗略使用方法

流过昼夜 提交于 2019-11-28 03:24:22
cp的一些常用的命令 -a 相当于-dr -d 若为链接文件就复制链接而非文件本身 -r 复制文件夹 -i 询问 -u 比较两文件,若要复制的文件比要被覆盖的文件新才会进行复制 -f 强制 -p 把属性一同复制过去 举例 root@DESKTOP-FA1P4IO:~# ls -l --time={atime,ctime} 12.txt #显示源文件信息日期是八月5号 -rwxrw-rw- 1 sys001 root 84 Aug 5 12:59 12.txt root@DESKTOP-FA1P4IO:~# cp 12.txt test1/12.txt # 复制 root@DESKTOP-FA1P4IO:~# ls -l --time={atime,ctime} 12.txt #源文件的属性修改时间没有变 -rwxrw-rw- 1 sys001 root 84 Aug 5 12:59 12.txt root@DESKTOP-FA1P4IO:~# ls -l test1/12.txt # 显示复制过去的文件信息,显示八月21号(复制源文件过来的时间)创建 -rwxrw-rw- 1 root root 84 Aug 21 14:39 test1/12.txt root@DESKTOP-FA1P4IO:~# cp -p 12.txt test1/12.txt # 重新复制,采用-p

Calculating time of execution with time() function

依然范特西╮ 提交于 2019-11-28 02:24:47
I was given the following HomeWork assignment, Write a program to test on your computer how long it takes to do nlogn, n2, n5, 2n, and n! additions for n=5, 10, 15, 20. I have written a piece of code but all the time I am getting the time of execution 0. Can anyone help me out with it? Thanks #include <iostream> #include <cmath> #include <ctime> using namespace std; int main() { float n=20; time_t start, end, diff; start = time (NULL); cout<<(n*log(n))*(n*n)*(pow(n,5))*(pow(2,n))<<endl; end= time(NULL); diff = difftime (end,start); cout <<diff<<endl; return 0; } Execute each calculation

Django的缓存机制

自闭症网瘾萝莉.ら 提交于 2019-11-27 18:27:54
由于Django是动态网站,所有每次请求均会去数据进行相应的操作,当程序访问量大时,耗时必然会更加明显,最简单解决方式是使用:缓存,缓存将一个某个views的返回值保存至内存或者memcache中,5分钟内再有人来访问时,则不再去执行view中的操作,而是直接从内存或者Redis中之前缓存的内容拿到,并返回。 Django中提供了6种缓存方式: 开发调试 内存 文件 数据库 Memcache缓存(python-memcached模块) Memcache缓存(pylibmc模块) 通用配置 'TIMEOUT': 300, # 缓存超时时间(默认300,None表示永不过期,0表示立即过期) 'OPTIONS':{ 'MAX_ENTRIES': 300, # 最大缓存个数(默认300) 'CULL_FREQUENCY': 3, # 缓存到达最大个数之后,剔除缓存个数的比例,即:1/CULL_FREQUENCY(默认3) }, 'KEY_PREFIX': '', # 缓存key的前缀(默认空) 'VERSION': 1, # 缓存key的版本(默认1) 'KEY_FUNCTION' 函数名 # 生成key的函数(默认函数会生成为:【前缀:版本:key】) 以上六中模式都可以使用 自定义key def default_key_func(key, key_prefix, version):

Python连载31-threading的使用

谁说胖子不能爱 提交于 2019-11-27 17:04:57
一、 例子:我们对传参是有要求的必须传入一个元组,否则报错 二、 import _thread as thread import time def loop1(in1): print("Start loop 1 at:",time.ctime()) print("我是参数",in1) time.sleep(4) print("End loop 1 at:",time.ctime()) def loop2(in1,in2): print("Start loop 2 at:",time.ctime()) print("我是参数",in1,"和参数 ",in2) time.sleep(4) print("End loop 1 at:",time.ctime()) def main(): print("Starting at:",time.ctime()) thread.start_new_thread(loop1,("liuming",)) #上面我们传参的时候,我用的是:(“liuming”),这里面是没有逗号的,结果编译报错,告诉我,这里面必须传入元组 #因此,我才在里面加了一个逗号,使其变成一个元组 thread.start_new_thread(loop2,("zhanglei","liuhao")) print("All done at:",time.ctime()) if _

Calculating time of execution with time() function

元气小坏坏 提交于 2019-11-27 04:54:37
问题 I was given the following HomeWork assignment, Write a program to test on your computer how long it takes to do nlogn, n2, n5, 2n, and n! additions for n=5, 10, 15, 20. I have written a piece of code but all the time I am getting the time of execution 0. Can anyone help me out with it? Thanks #include <iostream> #include <cmath> #include <ctime> using namespace std; int main() { float n=20; time_t start, end, diff; start = time (NULL); cout<<(n*log(n))*(n*n)*(pow(n,5))*(pow(2,n))<<endl; end=