python中怎么写一个替代txt文本所有回车为空格的程序 ,使文本只有了连续一行 ?

每次翻译外文文献的时候,把英文复制到谷歌翻译,会出现PDF格式的文本的换行很麻烦,需要手动来删除换行,影响翻译时思考的质量。

于是,我可不可以用python来解决这个问题呢?

with open('etext.txt','r') as fp:
    data = fp.readlines()
data = [line.strip() for line in data]
data = ','.join(data)
data = data.split(',')
data = ' '.join(map(str,data))
with open('welltext.txt','w') as fp:
    fp.write(data)

这样就能将

It is widely recognized that a visual texture, which humans
can easily perceive, is very difficult to define [17]. The difficulty
results mainly from the fact that different people can define textures
in application-dependent ways or with different perceptual
motivations, and there is no generally agreed-upon definition
[44]. It is not our intention to add here a new one: we simply
observe that it should be as general as possible, because a too
strict definition would allow one to confine his/her work to images
that better fit with it, eventually leading to narrow-domain
solutions.

转换成

It is widely recognized that a visual texture  which humans can easily perceive  is very difficult to define [17]. The difficulty results mainly from the fact that different people can define textures in application-dependent ways or with different perceptual motivations  and there is no generally agreed-upon definition [44]. It is not our intention to add here a new one: we simply observe that it should be as general as possible  because a too strict definition would allow one to confine his/her work to images that better fit with it  eventually leading to narrow-domain solutions.

在谷歌翻译里就是从这样


到这样




  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,以下是一个 Python 代码段,用于打开文本文件并修改其一行的二进制数据。在这个例子,我们假设你想修改第三行(从 0 开始计数)并且该行带有空格: ```python # 打开文本文件 with open("example.txt", "r") as file: # 读取文件内容并将每一行存储为列表 lines = file.readlines() # 获取第三行并将其转换为二进制数据 line_index = 2 # 第三行的索引是 2(从 0 开始计数) line = lines[line_index] binary_data = bytearray(line, "utf-8") # 修改二进制数据 binary_data[0] = 0b01010101 # 用二进制表示法设置第一个字节的值 # 将修改后的二进制数据转换回文本格式 modified_line = binary_data.decode("utf-8") # 将修改后的行替换回原始列表 lines[line_index] = modified_line # 将修改后的列表回文件 with open("example.txt", "w") as file: file.writelines(lines) ``` 在这个例子,我们首先使用 `readlines()` 方法读取文件内容并将每一行存储为一个字符串列表。然后,我们从列表获取第三行,并将其转换为二进制数据。接下来,我们使用标准的 Python 字节操作修改二进制数据(在这个例子,我们使用二进制表示法将第一个字节设置为 `01010101`)。然后,我们将修改后的二进制数据转换回文本格式,并将其替换回原始列表的第三行。最后,我们使用 `writelines()` 方法将修改后的行回原始文件。 请注意,这个例子假设你想修改第三行并且该行带有空格。如果你需要修改不同的行或不同的字符串,请相应地更改代码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yantuguiguziPGJ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值