json pickle time


多层装饰器:

字符串格式化:
当字符串格式化时 , %%

生成器
使用函数创造的
yield
递归
模块
PY:模块
其他:类库
先导入
后使用

自定义模块
内置模块
第三方模块
为什么要有模块
将代码归类
模块的内容很重要
导入模块依据
import sys
sys.path()
from xx import
单模块
import 导入
嵌套
from XXX imort XXX
as 别名

pip3 安装

pip3 install 模块
源码
tar
cd
python3 install setup.py

序列化相关
import json
import pickle
json
dic = {'k':1}
sdit = json.dumps(dic)
在内存中
json.dumps()---python 基本类型转换成字符串
json.loads() -----将字符串(基本类型)转成基本类型 反序列是一定使用 “” 双引号
在文件中
json.dump(s,open(file,w)) python 基本类型转换成字符串顺便写入文件
json.load(open(file,r)) 将字符串(基本类型)转成基本类型 反序列是一定使用 “” 双引号

pickle-----适合python复杂类型
只python用
pickle.dumps()
pickle.loads()
pickle.dump()
pickle.loads()
json/pickle
json 更加适合夸语言,字符串,基本数据类型
pickle,python 所有类型的序列化,仅仅使用python


import time
time.time() --- 时间戳
time.ctiem() 可以参数 ----当前系统时间
gsm = time.gmtime() 可以加时间戳参数 获取详细值 自定义返回值
localtime() ---本地时间
mktime(时间对象)---把时间对象转成时间戳
time.strftime('%y%m%d',time.local.time)
time.strptime

improt datetime
datetime.date.today()
new_time = datetime.datetime.nwo()+

import time
import datetime

print(time.clock()) #返回处理器时间,3.3开始已废弃
print(time.process_time()) #返回处理器时间,3.3开始已废弃
print(time.time()) #返回当前系统时间戳
print(time.ctime()) #输出Tue Jan 26 18:23:48 2016 ,当前系统时间
print(time.ctime(time.time()-86640)) #将时间戳转为字符串格式
print(time.gmtime(time.time()-86640)) #将时间戳转换成struct_time格式
print(time.localtime(time.time()-86640)) #将时间戳转换成struct_time格式,但返回 的本地时间
print(time.mktime(time.localtime())) #与time.localtime()功能相反,将struct_time格式转回成时间戳格式
#time.sleep(4) #sleep
print(time.strftime("%Y-%m-%d %H:%M:%S",time.gmtime()) ) #将struct_time格式转成指定的字符串格式
print(time.strptime("2016-01-28","%Y-%m-%d") ) #将字符串格式转换成struct_time格式

#datetime module

print(datetime.date.today()) #输出格式 2016-01-26
print(datetime.date.fromtimestamp(time.time()-864400) ) #2016-01-16 将时间戳转成日期格式
current_time = datetime.datetime.now() #
print(current_time) #输出2016-01-26 19:04:30.335935
print(current_time.timetuple()) #返回struct_time格式

#datetime.replace([year[, month[, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]]]]])
print(current_time.replace(2014,9,12)) #输出2014-09-12 19:06:24.074900,返回当前时间,但指定的值将被替换

str_to_date = datetime.datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M") #将字符串转换成日期格式
new_date = datetime.datetime.now() + datetime.timedelta(days=10) #比现在加10天
new_date = datetime.datetime.now() + datetime.timedelta(days=-10) #比现在减10天
new_date = datetime.datetime.now() + datetime.timedelta(hours=-10) #比现在减10小时
new_date = datetime.datetime.now() + datetime.timedelta(seconds=120) #比现在+120s
print(new_date)

posted @ 2016-06-08 11:22  eggtea  阅读(104)  评论(0)    收藏  举报