In the early days of Colab you could have used Ipython magic commands. Use below command
%pycat code.py
A pop up will appear displaying the code. You can copy it and edit it locally.
Remove the file using below command
!rm code.py
Copy the edited code to a cell in notebook and add below command at the top of the cell
%%writefile code.py
Run the cell. A file will be created with the contents present in the cell.
Updates:
Now there are lot more easy and convenient options.
- In the files section, there is an option to upload files or you can double click on the file, make changes and ctrl+s to save those changes.
- You can also use https://github.com/abhishekkrthakur/colabcode to edit using visual studio code server.