我有一个单词列表,其中包含用于分隔每个新字母的返回.有没有办法在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)