使用os.remove(file_path)即可,但是如果文件不存在会报错,所以实际使用时需要判断一下文件是否存在 案例 import os def remove_file(file_path): if os.path.exists(file_path): os.remove(file_path) if __name__ == '__main__': with open('d.txt', 'w') as file: file.write('a') remove_file('d.txt')