Python:如何从文本文件中删除所有引号?

Sha*_*ang 1 python text

我有一个文本文件,其格式为'"。该文本文件具有以下形式。

"string1", "string2", 'string3', 'string4', ''string5'', etc. 
Run Code Online (Sandbox Code Playgroud)

如何删除所有引用'"并保留文件的其余部分不变?

我怀疑应该是这样的:

with open('input.txt', 'r') as f, open('output.txt', 'w') as fo:
    for line in f:
        fo.write(line.strip())
Run Code Online (Sandbox Code Playgroud)

line.strip()某种程度上去除引号的字符串。还有其他要求吗?

Rob*_*obᵩ 5

你近了 相反str.strip(),请尝试str.replace()

with open('input.txt', 'r') as f, open('output.txt', 'w') as fo:
    for line in f:
        fo.write(line.replace('"', '').replace("'", ""))
Run Code Online (Sandbox Code Playgroud)