如何在Python中基于反斜杠条件合并不同行的文本? [英] How to merge text of different line based on backslash condition in Python?

查看:72
本文介绍了如何在Python中基于反斜杠条件合并不同行的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入文件文字:



你好\

早安\

所有

程序员



最后的文字应该是

Hello Good Morning All



合并应该是包含反斜杠的行号+ 1



我尝试过:



Input File Text:
Hi
Hello \
Good Morning \
All
Programmers

The final text should be
Hello Good Morning All

The Merging Should be The Line number Which contains backslash + 1

What I have tried:

if line.find('\\')!=-1:
                 print(LineNumber)
                 LineNumber += 1





但我不知道达到/重新下一行和合并的进一步逻辑。



But i don't know the further logic for reaching/retriving nextline and merging.

推荐答案

您已经在 https://www.codeproject.com/Questions/1254672/What-is-the-regular-expression-for-finding-line-en [ ^ ],并收到建议的解决方案。请不要重新发布相同的问题。



参见 5。内置类型 - Python 2.7.15文档 [ ^ ]。
You already posted this question at https://www.codeproject.com/Questions/1254672/What-is-the-regular-expression-for-finding-line-en[^], and received a suggested solution. Please do not repost the same question.

See also 5. Built-in Types — Python 2.7.15 documentation[^].


引用:

抱歉,但那不是解决方案。它用于正则表达式,这个用于合并。

Sorry,But That is not the solution of this.It was for regular expression and this one is for merging.



你从错误的一端解决问题。

不拆分文本文件,你只是没有合并问题。

在你的另一个问题中查看我的解决方案。


You take the problem from wrong end.
Don't split the text file and you will just don't have the merging problem.
See my solution in your other question.


这篇关于如何在Python中基于反斜杠条件合并不同行的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆