Google Colab - writing out a .csv but overwriting file?

Viewed 196

I'm hoping this is a straightforwardly simple thing to do, but I can't find a solution for. I'm using Google Colab to process some data on a daily basis that I then read into another program. I use:

files.download('today_out.csv')

It outputs to my windows/user/downloads directory. I would like, if possible, to be able to overwrite this file - but the Windows file system end up creating a today_out.csv(1) and I'd rather just overwrite the existing today_out.csv. Is there a way to do this in Colab?

1 Answers

It is not possible to read local files on your computer from Colab. But you can create a local python script and run it before running Colab.

Before downloading the file, you can check if the file exists and delete it.

try:
    os.remove("file.csv")
except OSError:
    pass

Related