假设这是字符串:
The fox jumped over the log.
Run Code Online (Sandbox Code Playgroud)
这将导致:
The fox jumped over the log.
Run Code Online (Sandbox Code Playgroud)
什么是最简单的1-2衬垫可以做到这一点?没有分裂并进入列表......
我有这个清单:
words = ['how', 'much', 'is[br]', 'the', 'fish[br]', 'no', 'really']
Run Code Online (Sandbox Code Playgroud)
我想要的是取代[br]
一些类似的奇妙价值<br />
,从而得到一个新的清单:
words = ['how', 'much', 'is<br />', 'the', 'fish<br />', 'no', 'really']
Run Code Online (Sandbox Code Playgroud) 我有一个单词列表,其中包含用于分隔每个新字母的返回.有没有办法在Python中使用文件I/O以编程方式删除每个返回?
编辑:我知道如何操纵字符串来删除返回.我想物理编辑该文件,以便删除这些返回.
我正在寻找这样的东西:
wfile = open("wordlist.txt", "r+")
for line in wfile:
if len(line) == 0:
# note, the following is not real... this is what I'm aiming to achieve.
wfile.delete(line)
Run Code Online (Sandbox Code Playgroud)