使用 Python 脚本和 VSCode 任务系统

1. 编写 Python 脚本

创建一个 Python 脚本,使用文件 I/O 和字符串替换功能来读取文本文件,替换 ' ' 字符,然后保存修改后的内容。

# remove_nonbreaking_spaces.py  
import codecs  
import sys  

def remove_nonbreaking_spaces(input_file, output_file):  
    with codecs.open(input_file, 'r', 'utf-8') as f:  
        content = f.read()  

    content_without_nbs = content.replace(' ', '')  # 替换  

    with codecs.open(output_file, 'w', 'utf-8') as f:  
        f.write(content_without_nbs)  

if __name__ == '__main__':  
    if len(sys.argv) != 3:  
        print("Usage: python remove_nonbreaking_spaces.py input_file output_file")  
        sys.exit(1)  

    input_f

你可能感兴趣的:(#,python,编程,vscode,python,ide)