python开发_difflib字符串比较
在python的difflib中
HtmlDiff:比较后以html方法展示

我们比较的是字符串:
'hello world!' 和 'hElLO Wor2d!'
具体代码:
from difflib import *
import os def write():
if os.path.exists('E:\\info.html'):
with open('E:\\info.html','w+') as fp:
test = HtmlDiff.make_file(HtmlDiff(), 'hello world!', 'hElLO Wor2d!')
fp.write(test)
print('生成文件成功!')
fp.close() def main():
write() if __name__ == '__main__':
main()

运行代码:
import difflib
test = difflib.Differ().compare('hello world', 'HeLLO,wOrlD!')
print('横向展示:')
print(''.join(list(test)))
print('#' * 50)
test = difflib.Differ().compare('hello world', 'HeLLO,wOrlD!')
print('纵向展示:')
print('\n'.join(list(test)))

运行代码:
import difflib def test():
test = difflib.SequenceMatcher(lambda x: x == " ", 'hello world', 'HeLLO,wOrlD!')
for block in test.get_matching_blocks():
print("a[%d] and b[%d] match for %d elements" % block) def main():
test() if __name__ == '__main__':
main()
python开发_difflib字符串比较的更多相关文章
- Python 开发基础-字符串类型讲解(字符串方法)-2
s = 'Hello World!'print(s.index('W',0,9))#返回某个字母的索引值,本例返回6.没有该字母会报错,和FIND比较像,find不会报错,没找到会返回-1print( ...
- Python 开发基础-字符串类型讲解(字符串方法)-1
s = 'Hello World!' print(s.capitalize()) #第一个字母大写,其余小写# 输出:Hello world!print(s.swapcase())#大写变小写,小写变 ...
- Python开发【字符串格式化篇】
1.百分号 __author__ = "Tang" # + 号 拼接 msg = "i am " + " tang" print(msg) ...
- python开发学习-day01 (python安装与版本、字符串、字典、运算符、文件)
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- python开发_python中字符串string操作
在python中,对于字符串string的操作,我们有必要了解一下,这样在我们的以后的开发中会给我们带来很多方便 下面是我学习的笔记: #python-string #python中的字符串用单引号' ...
- python开发:python字符串操作方法
name = "my \tname is {name} and i am {year} old" capitalize:第一个单词的首字母大写的方法 print(name.capi ...
- Python开发【第五篇】字符串
字符串 作用:用来记录文字信息 例子: 空字符串 '' #单引号空字符串 "" #双引号空字符串 ''' ''' #三单引号空字符串 """ &quo ...
- Python 开发轻量级爬虫07
Python 开发轻量级爬虫 (imooc总结07--网页解析器BeautifulSoup) BeautifulSoup下载和安装 使用pip install 安装:在命令行cmd之后输入,pip i ...
- Python 开发轻量级爬虫06
Python 开发轻量级爬虫 (imooc总结06--网页解析器) 介绍网页解析器 将互联网的网页获取到本地以后,我们需要对它们进行解析才能够提取出我们需要的内容. 也就是说网页解析器是从网页中提取有 ...
随机推荐
- hdu 5373 The shortest problem(杭电多校赛第七场)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5373 The shortest problem Time Limit: 3000/1500 MS (J ...
- 在wamp下增加多版本的PHP(PHP5.3,PHP5.4,PHP5.5)支持
1.安装WAMPServer 根据自己的操作系统选择相应的WAMP版本,我这里选择WAMPSERVER-32 BITS & PHP 5.5-2.5, 双击安装,选择安装目录即可,超级简单.根据 ...
- JSON.parse()——json字符串转JS
JSON 通常用于与服务端交换数据. 在接收服务器数据时一般是字符串. 我们可以使用 JSON.parse() 方法将数据转换为 JavaScript 对象. 语法 JSON.parse(text[, ...
- Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070058 android-studio 3.0 from canary 5 to canary 6
我升级android-studio到了3.0 canary 6打包编译安装出现如下错误: 07-11 13:00:39.523 8913-8913/dcpl.com.myapplication E/A ...
- Java集合里的一些“坑”
这里主要谈下Java集合在使用中容易被忽略.又容易出现的两个“坑”,一个是集合与数组互相转换,另一个是集合遍历删除.主要通过代码演示. 一.集合与数组互相转换中的“坑” //Test1.java pa ...
- 网页转图片,html生成图片,网页生成图片(基于linnux+phantomjs)和wkhtmltoimage
安装扩展: (1)下面是我在linux上的安装过程,如果没有安装git请先yum install git 安装casperjs cd / git clone git://githu ...
- 日志生成控制文件syslog.conf
1: syslog.conf的介绍 对于不同类型的Unix,标准UnixLog系统的设置,实际上除了一些关键词的不同,系统的syslog.conf格式是相同的.syslog采用可配置的.统一的系统登记 ...
- ASPLOS'17论文导读——SC-DCNN: Highly-Scalable Deep Convolutional Neural Network using Stochastic Computing
今年去参加了ASPLOS 2017大会,这个会议总体来说我感觉偏系统和偏软一点,涉及硬件的相对少一些,对我这个喜欢算法以及硬件架构的菜鸟来说并不算非常契合.中间记录了几篇相对比较有趣的paper,今天 ...
- linux sed命令查询结果前后批量追加内容(html文件批量修改css,js等文件路径)
1.需求:linux使用shell命令查询结果前后批量追加内容 例如:我需要在当前目录下所有的css文件路径前追加域名 我想的是用sed替换去实现,鲍哥的思路是用for循环 1.1方法1:鲍哥的for ...
- EasyUi – 2.布局Layout + 3.登录界面
1.页面布局 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.a ...