Importing .py files in Google Colab

前端 未结 10 2157
清酒与你
清酒与你 2020-11-28 22:38

Is there any way to upload my code in .py files and import them in colab code cells?

The other way I found is to create a local Jupyter notebook then upload it to C

10条回答
  •  情话喂你
    2020-11-28 23:31

    Based on the answer by Korakot Chaovavanich, I created the function below to download all files needed within a Colab instance.

    from google.colab import files
    def getLocalFiles():
        _files = files.upload()
        if len(_files) >0:
           for k,v in _files.items():
             open(k,'wb').write(v)
    getLocalFiles()
    

    You can then use the usual 'import' statement to import your local files in Colab. I hope this helps

提交回复
热议问题