简体   繁体   English

%load 魔术不会将文件加载到单元格中

[英]%load magic doesn't load file into cell

I am trying to use %load localfolder/something.txt in google colab and nothing shows up.我正在尝试在 google colab 中使用%load localfolder/something.txt但没有任何显示。

The same happens when I try to %load something from a remote location.当我尝试从远程位置%load某些内容时,也会发生同样的情况。

Note that when the file location does not exist, the magic command throws an error.请注意,当文件位置不存在时,magic 命令会抛出错误。 When it exists it remains silent.当它存在时,它保持沉默。

The magic command %load is listed in %lsmagic but doesn't seem to be doing its job.魔术命令%load%lsmagic中列出,但似乎没有发挥作用。

I am looking for either (a) some magic trick to make %load load file content into my cell or (b) some other way of efficiently loading text into a colab cell.我正在寻找 (a) 一些使 %load 将文件内容加载到我的单元格中的魔术,或者 (b) 一些其他有效地将文本加载到 colab 单元格中的方法。

Context: I am teaching a class.背景:我正在上课。 I would like to provide solutions to exercises via this mechanism.我想通过这种机制为练习提供解决方案。 I am currently going with !cat on some local files我目前在一些本地文件上使用!cat

Here is an example: https://colab.research.google.com/github/eickenberg/bug-free-garbanzo/blob/master/Untitled.ipynb这是一个示例: https ://colab.research.google.com/github/eickenberg/bug-free-garbanzo/blob/master/Untitled.ipynb

Note that in the notebook the local file doesn't exist, but the remote one does.请注意,在笔记本中,本地文件不存在,但远程文件存在。 The local one could be obtained by cloning the repo.本地的可以通过克隆 repo 获得。 But that also doesn't work.但这也行不通。

This is https://github.com/googlecolab/colabtools/issues/42 (sorry, no clever workaround beyond what you already have with cat & copy/paste).这是https://github.com/googlecolab/colabtools/issues/42 (抱歉,除了你已经拥有的 cat & copy/paste 之外没有聪明的解决方法)。

There are some ways to import data to a Google Colab notebook like files.upload function and importing directly from Google Drive using drive.mount function.有一些方法可以将数据导入 Google Colab 笔记本,例如files.upload函数和使用drive.mount函数直接从 Google Drive 导入。 I recommend you to read this nice guide to learn about importing data to Google Colab.我建议您阅读这个不错的指南,了解如何将数据导入 Google Colab。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM