我正在尝试从文件中删除所有(非空格)空白字符并用逗号替换所有空格。这是我当前的代码:
def file_get_contents(filename):
with open(filename) as f:
return f.read()
content = file_get_contents('file.txt')
content = content.split
content = str(content).replace(' ',',')
with open ('file.txt', 'w') as f:
f.write(content)
当它运行时,它将文件的内容替换为:
<built-in,method,split,of,str,object,at,0x100894200>