如何在Google Colab中编辑和保存文本文件(.py)? [英] How to edit and save text files (.py) in Google Colab?
问题描述
我使用!git clone https://github.com/llSourcell/Pokemon_GAN.git
克隆了一个github仓库.我想在Colab中修改.py文件.所以我按照这里的建议使用了%load filename.py
(
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
将编辑后的代码复制到笔记本中的单元格中,并在单元格顶部添加以下命令
%%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.
这篇关于如何在Google Colab中编辑和保存文本文件(.py)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!