Python | redlines 模块 |生成显示两个文本之间的差异

本文介绍了如何使用Python库redlines来直观比较两个文本,展示了如何通过ChatGPT辅助检查英语语法,并以Markdown格式展示文本差异。作者分享了使用示例和对库的评价。
摘要由CSDN通过智能技术生成

如是我闻: 用ChatGPT来帮我检查英语语法,是我使用最多的一个场景。最近发现了一个可以直观显示修改过后的文本差异的Pyhton库,这里将它的用法总结一下。

效果展示:
在这里插入图片描述

  1. 下载redlines
pip install redlines
  1. redlines基本使用
from redlines import Redlines
from IPython.display import Markdown, display


text = f"""
Got this for my daughter for her birthday cuz she keeps taking \
mine from my room.  Yes, adults also like pandas too.  She takes \
it everywhere with her, and it's super soft and cute.  One of the \
ears is a bit lower than the other, and I don't think that was \
designed to be asymmetrical. It's a bit small for what I paid for it \
though. I think there might be other options that are bigger for \
the same price.  It arrived a day earlier than expected, so I got \
to play with it myself before I gave it to my daughter.
"""

reponse = f"""
Got this for my daughter for her birthday because she keeps taking mine from my room. Yes, adults also like pandas too. She takes it everywhere with her, and it's super soft and cute. However, one of the ears is a bit lower than the other, and I don't think that was designed to be asymmetrical. Additionally, it's a bit small for what I paid for it. I believe there might be other options that are bigger for the same price. On the positive side, it arrived a day earlier than expected, so I got to play with it myself before I gave it to my daughter."""

diff = Redlines(text, reponse) # 对比两段文本
display(Markdown(diff.output_markdown)) # 以Markdown输出

输出:
在这里插入图片描述

更多说明: redlines 0.4.2

非常的有品

以上

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值