用python删除多个csv文件的内容

2024-03-29 01:44:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用以下代码删除单个csv文件的内容:

filename = "output.csv"
# opening the file with w+ mode truncates the file
f = open(filename, "w+")
f.close()

有没有办法同时处理同一文件夹中的多个csv文件?基本上我想保留文件名,只删除它们的内容。你知道吗


Tags: 文件csvthe代码内容closeoutputmode