How to edit and save text files (.py) in Google Colab?

后端 未结 11 1805
[愿得一人]
[愿得一人] 2020-12-24 01:16

I cloned a github repo using !git clone https://github.com/llSourcell/Pokemon_GAN.git. I wanted to modify a .py file inside Colab. So i used %load fil

相关标签:
11条回答
  • 2020-12-24 01:56

    Solution:

    p = """
    Yadda yadda
    whatever you want just don't use triple quotes.
    """
    
    c = """text_file = open("text.text", "w+");text_file.write(p);text_file.close()""" 
    
    exec(c)
    
    0 讨论(0)
  • 2020-12-24 01:57

    I found it easier to edit the file locally.

    1. You can download it from the left panel.
    2. Right click on any file and download it.
    3. Next, edit the file.
    4. Next, upload the file.
    5. use mv to move the file to the right location.

    0 讨论(0)
  • 2020-12-24 01:58

    Not a perfect solution but can be useful for someone.

    You can use !cat file_name.py to access file_name.py contents, copy the contents in the next cell and now you can run it or edit it.

    0 讨论(0)
  • 2020-12-24 01:58

    There is an app called Python Compiler Editor that you can connect to your Google Drive account, edit files and save them back.

    0 讨论(0)
  • 2020-12-24 02:04

    While I don't have a way of editing in the notebook, I will share my pipeline. Quite obvious really:

    • fork the repo or create a new one(for a new project)
    • create a branch just for uploading
    • make changes and push
    • evaluate
    • make changes

    Hope that helps.

    0 讨论(0)
提交回复
热议问题