2024-10-02 00:31:56 发布
网友
我使用以下代码删除单个csv文件的内容:
filename = "output.csv" # opening the file with w+ mode truncates the file f = open(filename, "w+") f.close()
有没有办法同时处理同一文件夹中的多个csv文件?基本上我想保留文件名,只删除它们的内容。你知道吗
您可以使用标准库中的^{}包来获取目录中按扩展名列出的文件列表:
import glob for csv_file in glob.glob("*.csv"): open(csv_file, "w+").close()
您可以使用标准库中的^{} 包来获取目录中按扩展名列出的文件列表:
相关问题 更多 >
编程相关推荐