4.15Day20加密模块,表格操作模块
今日内容: hashlib模块:加密 hmac模块:加密 configparser模块:操作配置文件 subprocess模块:操作shell命令 xlrd模块:excel读 xlwt模块:excel写 xml模块
一、hashlib模块:加密 import hashlib# 基本使用cipher = hashlib.md5('需要加密的数据的二进制形式'.encode('utf-8'))print(cipher.hexdigest()) # 加密结果码 # 加盐cipher = hashlib.md5()cipher.update('前盐'.encode('utf-8'))cipher.update('需要加密的数据'.encode('utf-8'))cipher.update('后盐'.encode('utf-8'))print(cipher.hexdigest()) # 加密结果码 # 其他算法cipher = hashlib.sha3_256(b'')print(cipher.hexdigest())cipher = hashlib.sha3_512(b'')print(cipher.hexdigest()) 二、hmac模块:加密 # 必须加盐cipher = hmac.new('盐'.encode('utf-8'))cipher.update('数据'.encode('utf-8'))print(cipher.hexdigest()) 三、configparser模块:操作配置文件 # my.ini# 注释:该配置文件中,值直接书写,但有四种类型# -- int float boolean str# section[server]# name:option | value:mysqlname = mysqlversion = 20000 [client]name = owenadress = 192.168.11.174 import configparser# 初始化配置文件的操作对象parser = configparser.ConfigParser()# 读parser.read('my.ini', encoding='utf-8')# 所有sectionprint(parser.sections())# 某section下所有optionprint(parser.options('section_name'))# 某section下某option对应的值print(parser.get('section_name', 'option_name')) # 写parser.set('section_name', 'option_name', 'value')parser.write(open('my.ini', 'w')) 四、subprocess模块:操作shell命令 import subprocessorder = subprocess.Popen('终端命令', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)# order.stdout 流对象,order.stdout.read()来获取操作的信息字符串suc_res = order.stdout.read().decode('系统默认编码')err_res = order.stderr.read().decode('系统默认编码') # stdout:存放指令执行成功的信息管道 | stderr 存放指令执行失败的信息管道order = subprocess.run('终端命令', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)# order.stdout 是字符串信息,就是Popen下order.stdout.read()suc_res = order.stdout.decode('系统默认编码')err_res = order.stderr.decode('系统默认编码') 五、xlrd模块:excel读 年终报表 教学部 市场部 咨询部 总计Jan-19 10 15 5 30Feb-19 10 15 5 30Mar-19 10 15 5 30Apr-19 10 15 5 30May-19 10 15 5 30Jun-19 10 15 5 30Jul-19 10 15 5 30Aug-19 10 15 5 30Sep-19 10 15 5 30Oct-19 10 15 5 30Nov-19 10 15 5 30Dec-19 10 15 5 30 import xlrd# 读取文件work_book = xlrd.open_workbook("机密数据.xlsx")# 获取所有所有表格名称print(work_book.sheet_names())# 选取一个表sheet = work_book.sheet_by_index(1)# 表格名称print(sheet.name)# 行数print(sheet.nrows)# 列数print(sheet.ncols)# 某行全部print(sheet.row(6))# 某列全部print(sheet.col(6))# 某行列区间print(sheet.row_slice(6, start_colx=0, end_colx=4))# 某列行区间print(sheet.col_slice(3, start_colx=3, end_colx=6))# 某行类型 | 值print(sheet.row_types(6), sheet.row_values(6))# 单元格print(sheet.cell(6,0).value) # 取值print(sheet.cell(6,0).ctype) # 取类型print(sheet.cell_value(6,0)) # 直接取值print(sheet.row(6)[0])# 时间格式转换print(xlrd.xldate_as_datetime(sheet.cell(6, 0).value, 0)) 六、xlwt模块:excel写 import xlwt# 创建工作簿work = xlwt.Workbook()# 创建一个表sheet = work.add_sheet("员工信息数据")# 创建一个字体对象font = xlwt.Font()font.name = "Times New Roman" # 字体名称font.bold = True # 加粗font.italic = True # 斜体font.underline = True # 下划线# 创建一个样式对象style = xlwt.XFStyle()style.font = fontkeys = ['Owen', 'Zero', 'Egon', 'Liuxx', 'Yhh']# 写入标题for k in keys: sheet.write(0, keys.index(k), k, style)# 写入数据sheet.write(1, 0, 'cool', style)# 保存至文件work.save("test.xls") 七、xml模块<?xml version="1.0"?><data> <country name="Liechtenstein"> <rank updated="yes">2</rank> <year>2008</year> <gdppc>141100</gdppc> <neighbor name="Austria" direction="E"/> <neighbor name="Switzerland" direction="W"/> </country> <country name="Singapore"> <rank updated="yes">5</rank> <year>2011</year> <gdppc>59900</gdppc> <neighbor name="Malaysia" direction="N"/> </country> <country name="Panama"> <rank updated="yes">69</rank> <year>2011</year> <gdppc>13600</gdppc> <neighbor name="Costa Rica" direction="W"/> <neighbor name="Colombia" direction="E"/> </country></data> import xml.etree.ElementTree as ET# 读文件tree = ET.parse("xmltest.xml")# 根节点root_ele = tree.getroot()# 遍历下一级for ele in root_ele: print(ele) # 全文搜索指定名的子标签ele.iter("标签名")# 非全文查找满足条件的第一个子标签ele.find("标签名")# 非全文查找满足条件的所有子标签ele.findall("标签名") # 标签名ele.tag# 标签内容ele.text# 标签属性ele.attrib # 修改ele.tag = "新标签名"ele.text = "新文本"ele.set("属性名", "新属性值") # 删除sup_ele.remove(sub_ele) # 添加my_ele=ET.Element('myEle')my_ele.text = 'new_ele'my_ele.attrib = {'name': 'my_ele'}root.append(my_ele) # 重新写入硬盘tree.write("xmltest.xml")
转载于:https://www.cnblogs.com/shuchengyi/articles/10712951.html
4.15Day20加密模块,表格操作模块相关推荐
- Python操作Excel表格的模块xlrd的简单介绍
Python操作Excel表格的模块xlrd的简单介绍 处理数据对Python来说,比较容易,操作简单,功能强大,短短几行代码,就可处理大量的数据信息,下面介绍Python处理Excel表格的一个模块 ...
- Python3中的Excel表格操作
一.2003以前的表格以.xls后缀,用xlwt来写表格,用xlrd来读取表格:2007的表格以.xlsx后缀,用openpyxl来读写表格. 二.xlrd使用介绍 1.导入模块 import x ...
- Fintech系列(三) -- python对excel操作模块汇总||推荐指数||用法示例
python对excel操作模块汇总||推荐指数||用法示例 Working with Excel Files in Python 总览 读写Excel的python第三方开源模块 Excel写操作插 ...
- python通过什么连接数据库_python中常用的各种数据库操作模块和连接实例
这篇文章主要介绍了python中常用的各种数据库操作模块和连接实例,包括sqlite3.oracle.mysql.excel,需要的朋友可以参考下 工作中,经常会有用python访问各种数据库的需求, ...
- 4、jquery表格操作
1.<html> 2.<head> 3.<title>jquery表格操作</title> 4.<script language="ja ...
- python数据分析报告的格式_Python数据报表之Excel操作模块用法分析
本文实例讲述了Python数据报表之Excel操作模块用法.分享给大家供大家参考,具体如下: 一 点睛 Excel是当今最流行的电子表格处理软件,支持丰富的计算函数及图表,在系统运营方面广泛用于运营数 ...
- python处理excel表格实例-python2 对excel表格操作完整示例
本文实例讲述了python2 对excel表格操作.分享给大家供大家参考,具体如下: #!/usr/bin/env python2 # -*- coding: utf-8 -*- "&quo ...
- Python:目录和文件的操作模块os.path和OS常用方法
1.目录和文件的操作模块os.path,在使用之前要先导入:import os.path.它主要有以下几个重要的功能函数: #!/user/bin/python #coding= utf-8impor ...
- qq聊天界面 java程序 51cto_Java QQ项目详细设计之:组操作模块
好长时间没发博文了,今天再写点,今天写qq软件的组操作模块,由于客户端方面的组操作不需要复杂的逻辑,所以就不写客户端了,只写一下服务器端的组操作响应,好,先写一下伪码: 组操作模块 由于基本的几个组操 ...
- 原生js封装table表格操作,获取任意行列td,任意单行单列方法
V1.001更新增加findTable-min.js 本次更新,优化了代码性能方面,增加了部分新功能,可以获取多个table表格批量操作. 考虑到本人后面的项目中可能涉及到大量的表格操作,提前先封了 ...
最新文章
- HDU1756(判断一个点是否在多边形内)
- 48本3D视觉领域学习书籍,请自取
- MySQL遇到check the manual that corresponds to your MySQL server version for the right syntax错误
- 干掉了竞争对手的餐饮夫妻店,在等待自己的死亡
- java分页查询oracle_Java中实现Oracle分页查询
- less最后一页 linux_必备linux命令有哪些?你了解多少
- 支付宝WAP支付接口开发
- sql 数据库检查_数据库检查点– SQL Server 2016中的增强功能
- mybatis 批量插入的两种方式
- window文件恢复工具
- 赵雅智_java 数据库编程(1)
- 安装mathtype打开word报错 mathtype.Dll cannot be found 解决方式
- 使用网上软件激活win10后,默认谷歌浏览器被锁定hao123 解决思路
- 您有新的订单提示音在线试听_iPhone修改微信提示音,支持全部机型,无需越狱...
- python 基于金字塔的图像融合
- word论文页码从任意页开始编号
- Linux的磁盘分区、基本目录结构
- 数字藏品即是风口也是风险!
- Hololens官方教程精简版 - 08. Sharing holograms(共享全息影像)
- Caffe 代码解读之全连接层 inner product layer