(常用)time,datetime,random,shutil(zipfile,tarfile),sys模块
import time
1、时间戳 (时间秒数的表达形式, 从1970年开始)
print(time.time())
start_time=time.time()
time.sleep(3)
stop_time=time.time()
print(stop_time-start_time)
print(time.strftime('%Y-%m-%d %H:%M:%S %p'))
print(time.strftime('%Y-%m-%d %X %p'))
print(time.localtime()) # 上海:东八区
print(time.localtime().tm_year)
print(time.localtime().tm_mday)
print(time.gmtime()) # UTC时区
print(time.localtime(1111111111).tm_hour)
print(time.gmtime(1111111111).tm_hour)
print(time.mktime(time.localtime()))
print(time.strftime('%Y/%m/%d',time.localtime()))
print(time.strptime('2017/04/08','%Y/%m/%d'))
print(time.asctime(time.localtime()))
print(time.ctime(12312312321))


import datetime
print(datetime.datetime.now() + datetime.timedelta(days=3))
print(datetime.datetime.now() + datetime.timedelta(days=-3))
print(datetime.datetime.now() + datetime.timedelta(hours=3))
print(datetime.datetime.now() + datetime.timedelta(seconds=111))
current_time=datetime.datetime.now()
print(current_time.replace(year=1977))
print(datetime.date.fromtimestamp(1111111111))
print(datetime.date.fromtimestamp(time.time()) )
#时间戳直接转成日期格式 2018-04-08
import random
print(random.randint(1,3)) #大于等于1且小于等于3之间的整数
print(random.randrange(1,3)) #大于等于1且小于3之间的整数
print(random.choice([1,'a',[1,2,3]])) #从定义的列表中随机选取
print(random.sample([1,2,3,4,5],3)) #列表中元素任选(3)个数
print(random.uniform(1,3)) #大于1小于3的小数
item=[1,3,5,7,9]
random.shuffle(item) #打乱item的顺序相当于洗牌
print(item)
import random
res=''
for i in range(n):
s1=str(random.randint(0,9))
s2=chr(random.randint(65,90))
res+=random.choice([s1,s2])
return res
print(make_code(10))
if percent > 1:
percent=1 #防止显示百分数超过100%
show_str=('[%%-%ds]' %width) %(int(width*percent) * '#')
print('\r%s %d%%' %(show_str,int(100*percent)),end='')
recv_size=0
total_size=1111111
while recv_size < total_size:
time.sleep(0.1)
recv_size+=8096
percent=recv_size / total_size
progress(percent)
print('[%-30s]'%'#') # %-50s, -左对齐, 50宽度为50不够空格补
print(('[%%-%ds]'%width)%'#') #第一个百分号取消了第二个百分号的特殊含义
print('%s%%' %num) #30%
压缩
import shutil
import time
ret = shutil.make_archive(
"day15_bak_%s" %time.strftime('%Y-%m-%d'),
'gztar',
root_dir=r'D:\code\SH_fullstack_s1\day15'
)
import tarfile
t=tarfile.open('day15_bak_2018-04-08.tar.gz','r')
t.extractall(r'D:\code\SH_fullstack_s1\day16\解包目录')
t.close()
sys.argv
sys.path
import 放在一起
func()
(常用)time,datetime,random,shutil(zipfile,tarfile),sys模块的更多相关文章
- time/datetime/random/string/os/sys/shutil/zipfile/tarfile - 总结
		
time 模块: time.time() #时间戳 time.localtime() #当前时间对象元组 time.localtime(123123) #根据时间戳的时间对象 time.mktime( ...
 - 模块 - random/string/os/sys/shutil/zipfile/tarfile
		
random 模块 方法: >>> random.randint(1,3) #会包含 1 2 3 3 >>> random.randrange(1,3) #会包含 ...
 - python  time、datetime、random、os、sys模块
		
一.模块1.定义模块:用来从逻辑上组织Python代码(变量,函数,类,逻辑:实现一个功能),本质就是.py结尾的python文件(文件名:test.py,对应的模块名:test)包:用来从逻辑上组织 ...
 - 内置模块:time, datetime, random, json, pickle, os, sys, hashlib, collections, re
		
1.time模块 import time time.time() # 时间戳 浮点数 time.sleep() # 睡眠 time.gmtime()/time.localtime() #结构化时间 数 ...
 - 模块之 time datetime random json pickle os sys hashlib collections
		
目录 1. time模块 1.1表示时间的几种方式: 1.2格式化字符串的时间格式 1.3不同格式时间的转换 2.datetim模块 3.random模块 4. json模块 4.1dumps.loa ...
 - 序列化、time、random、hashlib、sys模块
		
•很多常用和内置模块,我们只需要掌握他们的用法而暂时不用考虑内部是如何实现的,这些模块大大提升了开发效率 ! 1.json模块与pickle模块 •json 如果你有这样的困扰,当希望把一种数据存到硬 ...
 - 包+time+datetime+random+hashlibhmac+typing+requests+re模块(day17整理)
		
目录 昨日内容 os模块 sys模块 json模块 pickle模块 logging模块 今日内容 包 相对导入 绝对导入 time模块 sleep 时间戳 time 格式化时间 strtime 结构 ...
 - python之random、time与sys模块
		
一.random模块 import random # float型 print(random.random()) #取0-1之间的随机小数 print(random.uniform(n,m)) #取 ...
 - collections,time,random,os, sys 模块的使用
		
主要内容:1. 模块的简单认识2. collections模块3. time时间模块4. random模块5. os模块6. sys模块 一. 模块的简单认识什么是模块. 模块就是我们把装有特定功能的 ...
 
随机推荐
- eclipse index 不工作 F3 不能找到头文件
			
To add paths containing code to parse, follow these steps :1. Right click on the project2. Select Pr ...
 - [luoguU42591][小T的面试题]
			
luoguU42591 题意: n个不超过n的正整数中,其中有一个数出现了两次,其余的数都只出现了一次, 求这个出现两次的数. 思路: 这个题的亮点在于内存限制1MB.明显不能再用数组储存了,肯定是用 ...
 - JasperReport 中踩过的坑
			
Mac Book Pro 10.13.6Jaspersoft Studio community version 6.6.9JDK 8 安装 Jaspersoft Studio Jasper Rep ...
 - 用socket写一个简单的客户端和服务端程序
			
用来练手写写socket代码 客户端代码 #include <stdio.h> #include <sys/types.h> #include <sys/socket.h ...
 - Elasticsearch日志分析系统
			
Elasticsearch日志分析系统 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.什么是Elasticsearch 一个采用Restful API标准的高扩展性的和高可用性 ...
 - php7连接 sqlserver踩过的坑,could not find driver解决方式
			
最近把环境升级为php7发现在连接sqlser的时候无法使用驱动了 页面错误 后来查看文档发现:php7应该采用Server=xxxx;DataBase=xxxxx 解决方式: DB_DSN_TWO ...
 - Python基础【day01】:python介绍发展史(一)
			
本节内容 Python介绍 发展史 Python 2 or 3? 一. Python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏 ...
 - mysql -- 慢日志使用
			
修改配置文件 show_query_log = OFF 是否开启慢日志查询 long_query_time = 2 时间限制,超过次时间,则记录 slow_query_log_file = /usr/ ...
 - centos7 memcached+magent+keepalived集群
			
111,222均部署keepalived,magent,memcached keepalived 111为主机,222为备机 其中,111上magent以本地memcache为主,222为备用 222 ...
 - <table>居中的一种方法
			
<div title="主页" data-options="iconCls:'icon-house'"> <center> <ta ...