如何在 Google Colab 中编辑和保存文本文件 (.py)? [英] How to edit and save text files (.py) in Google Colab?

查看:219
本文介绍了如何在 Google Colab 中编辑和保存文本文件 (.py)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 !git clone https://github.com/llSourcell/Pokemon_GAN.git 克隆了一个 github 存储库.我想在 Colab 中修改一个 .py 文件.所以我按照这里的建议使用了 %load filename.py (如何将文本文件 (.py) 加载/编辑/运行/保存到 IPython 笔记本单元格中?).但是每当我运行此命令时,我都会在一段时间后断开连接.我想知道是否有其他方法可以编辑 .py 文件,而无需经历将其下载到 PC、编辑然后重新上传的麻烦.提前致谢.

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 filename.py as suggested here (How to load/edit/run/save text files (.py) into an IPython notebook cell?). But whenever i run this command, i get disconnected after some time. I was wondering if there is some other way to edit .py file without undergoing the hassle of downloading it to pc,editing and then re uploading it. Thanks in advance.

推荐答案

您可以使用 Ipython 魔法命令.使用下面的命令

%pycat code.py

将出现一个弹出窗口,显示代码.您可以复制它并在本地进行编辑.
使用以下命令删除文件

!rm code.py

将编辑后的代码复制到 notebook 中的单元格中,并在单元格顶部添加以下命令

%%writefile code.py

运行单元格.将使用单元格中的内容创建一个文件.

You can use 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.

  1. 在文件部分,有一个上传文件的选项,或者您可以双击文件,进行更改并按 ctrl+s 保存这些更改.
  2. 您还可以使用 https://github.com/abhishekkrthakur/colabcode 使用 Visual Studio 进行编辑代码服务器.
  1. 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.
  2. You can also use https://github.com/abhishekkrthakur/colabcode to edit using visual studio code server.

这篇关于如何在 Google Colab 中编辑和保存文本文件 (.py)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆