json vs pickle

摘要: pickle: 只支持python,支持py里的所有数据类型(class-->object, function, datetime) 优点: 专为python设计,支持python所有的数据类型 缺点: 只能在python中使用,存储数据占空间大 json: 支持所有语言都支持, 只支持常规数据类型 阅读全文
posted @ 2019-06-21 14:40 kingforn 阅读(169) 评论(0) 推荐(0)

序列化pickle

摘要: import pickle d = { 'name':'alex', 'role':'police', 'blood': 76, 'weapon':'AK47' } d_dump = pickle.dumps(d) #序列化 print (pickle.loads(d_dump)) #反序列化 f 阅读全文
posted @ 2019-06-21 11:22 kingforn 阅读(119) 评论(0) 推荐(0)

随机数random模块

摘要: random随机模块 程序中有很多地方需要用到随机字符,比如登陆网站的随机验证码,通过random模块可以很容易生成随机字符。 >>> random.randrange(1, 10) #返回1-10之间的一个随机数,不包括10 >>> random.randint(1,10) #返回1-10之间的一 阅读全文
posted @ 2019-06-21 09:52 kingforn 阅读(209) 评论(0) 推荐(0)

datetime模块时间运算

摘要: datetime模块: 相比于time模块,datetime模块的接口则更直观、更容易调用 datetime模块定义了下面这几类: datetime.date:表示日期的类。常用的属性有year, month, day; datetime.time:表示时间的类。常用的属性有hour, minute 阅读全文
posted @ 2019-06-21 08:59 kingforn 阅读(815) 评论(0) 推荐(0)

time模块细讲

摘要: time模块的方法: time.localtime([secs]) :将一个时间戳转换为当前时区的struct_time。若secs 参数未提供,则以当前时间为准。 time.gmtime([secs]):和localtime()方法类似,gmtime()方法是将一个时间戳转换为UTC时区(0时区) 阅读全文
posted @ 2019-06-21 08:20 kingforn 阅读(151) 评论(0) 推荐(0)