Skip to content
SEO & Data Specialist | Arthur Camberlein
TwitterFRBlog FR

How to upload files in Google Colab

Python, Tips1 min read

If you like and enjoy using Notebook for Python (Google Colab, Jupyter, ...), you will be glad that there is a tip that could help you save some time to import files from your computer (or the one from the user of your app/scrip)

How to import and upload files in Google Colab - Arthur Camberlein

2 lines to create a prompt to import files from the user computer

Did you know that by using 2 lines of code you could easily import files in Google Colab? It's like a small user interface, like a prompt. This tip is like the input() code to get information from a user. In this case it will let them upload a file from their computer, to the notbook.

We will be using .upload() and create a variable. But first we need to import files from google.colab

1from google.colab import files
2file = files.upload()

If you want to know more about import, you should read Importing a library in Python

The (classic) drag and drop

Without using this prompt, there is still a drag and drop option directly on Google Colab. To do so, go to the Files tab on the left and you will be able to drag and drop 1 file or several files at once. Even a folder or a .zip file to unzip

In addition to that, the end user of your script will not be lost since it is the sanme behaviour as on their computer or lots of website in the web.

A gif to explain you how it works

How to import and upload files in Google Colab - Arthur Camberlein

© 2023 by SEO & Data Specialist | Arthur Camberlein. All rights reserved.
Theme by LekoArts