代码改变世界

随笔档案-2019年05月

json

2019-05-27 15:04 by Loker-X, 156 阅读, 收藏,
摘要: import jsonshopping = { 'name':'zhangwuji', 'age':'1999'}# f = open('json1.json','w')# f.write(json.dumps(shopping))# f.close()with open('j.json','w') 阅读全文

re正则

2019-05-17 14:15 by Loker-X, 299 阅读, 收藏,
摘要: Python 正则式的基本用法 1.1 基本规则 1.2 重复 1.2.1 最小匹配与精确匹配 1.3 前向界定与后向界定 1.4 组的基本知识 2. re 模块的基本函数 2.1 使用 compile 加速 2.2 match 和 search 2.3 finditer 2.4 字符串的修改与替换 阅读全文

配置文件

2019-05-10 17:51 by Loker-X, 233 阅读, 收藏,
摘要: import configparserconfig = configparser.ConfigParser()config["DEFAULT"] = {'ServerAliveInterval': '45', 'Compression': 'yes', 'CompressionLevel': '9' 阅读全文

logging日志模块

2019-05-09 09:52 by Loker-X, 268 阅读, 收藏,
摘要: import logging # 引入logging模块import os.pathimport time log = logging.getLogger()fh = logging.FileHandler('www.log')ch = logging.StreamHandler()format = 阅读全文

hashlib加密

2019-05-09 09:51 by Loker-X, 158 阅读, 收藏,
摘要: import _hashlibm = _hashlib.openssl_sha256() #创建一个加密对象m.update("JGood is a handsome boy".encode('utf8')) #更新要加密的数据print(m.digest()) #加密后的结果(二进制)print( 阅读全文

sys模块

2019-05-09 09:50 by Loker-X, 273 阅读, 收藏,
摘要: 导入sys模块 首先,打开终端模拟器进入Python解释器或者打开IDE编辑器创建一个新的.py后缀名的Python程序文件。 下面,以解释器中的操作举例: >>> import sys #导入sys模块>>> dir(sys) #dir()方法查看模块中可用的方法 注意:如果是在编辑器,一定要注意 阅读全文

os模块

2019-05-09 09:42 by Loker-X, 193 阅读, 收藏,
摘要: os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作目录;相当于shell下cd os.curdir 返回当前目录: ('.') os.pardir 获取当前目录的父目录字符串名:('..') os.makedirs 阅读全文

random模块

2019-05-05 13:26 by Loker-X, 148 阅读, 收藏,
摘要: Python中的random模块 Python中的random模块用于生成随机数。下面介绍一下random模块中最常用的几个函数。 random.random random.random()用于生成一个0到1的随机符点数: 0 <= n < 1.0 random.uniform random.uni 阅读全文

time模块

2019-05-05 13:24 by Loker-X, 212 阅读, 收藏,
摘要: 1、Python time time()方法 Python time time() 返回当前时间的时间戳(1970纪元后经过的浮点秒数)。 time()方法语法: 举例: 输出: 2、Python time localtime()方法 Python time localtime() 函数类似gmti 阅读全文

生成器和迭代器

2019-05-05 10:59 by Loker-X, 233 阅读, 收藏,
摘要: python 生成器和迭代器有这篇就够了 本节主要记录一下列表生成式,生成器和迭代器的知识点 列表生成器 首先举个例子 现在有个需求,看列表 [0,1,2,3,4,5,6,7,8,9],要求你把列表里面的每个值加1,你怎么实现呢? 方法一(简单): + View Code 方法二(一般): + Vi 阅读全文