似乎您无法直接编辑python文件,所以这是我的建议:
# first get all lines from filewith open('file.txt', 'r') as f: lines = f.readlines()# remove spaceslines = [line.replace(' ', '') for line in lines]# finally, write lines in the filewith open('file.txt', 'w') as f: f.writelines(lines)


