相关疑难解决方法(0)

删除文件输出中的换行符/返回载体

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

python io file

10
推荐指数
2
解决办法
7万
查看次数

标签 统计

file ×1

io ×1

python ×1