How to run a Python script in a '.py' file from a Google Colab notebook?

前端 未结 6 2123
星月不相逢
星月不相逢 2021-01-31 17:14
%%javascript
IPython.OutputArea.prototype._should_scroll = function(lines) {
    return false;
}

%run rl_base.py

I run this giving error saying rl_bas

6条回答
  •  庸人自扰
    2021-01-31 17:44

    When you run your notebook from Google drive, an instance is created only for the notebook. To make the other files in your Google drive folder available you can mount your Google drive with:

    from google.colab import drive
    drive.mount('/content/gdrive')
    

    Then copy the file you need into the instance with:

    !cp gdrive/My\ Drive/path/to/my/file.py .
    

    And run your script:

    !python file.py
    

提交回复
热议问题