【问题标题】:Python in Google Colaboratory - How to create, write and read files in google driveGoogle Colaboratory 中的 Python - 如何在 Google Drive 中创建、写入和读取文件
【发布时间】:2020-06-23 15:43:49
【问题描述】:

我尝试使用下面的代码创建一个文件,但是当我尝试在我的驱动器中搜索它时它不起作用。如果您需要查看完整内容,这是我的代码的链接。 https://colab.research.google.com/drive/1N436bntHOf146ZMGVBeSh5EXBuYAjvQY?usp=sharing

这是我用来创建和编写文件的代码。

output = open("sequences.fasta", "w")
output.writelines('>' + firstheader + '\n' + seq1 + '\n')
output.writelines('>' + secondheader + '\n' + seq2.upper() + '\n')
output.writelines('>' + thirdheader + '\n' + seq3.replace('-', '') + '\n') 

【问题讨论】:

    标签: python python-3.x file google-colaboratory


    【解决方案1】:

    设置

    你需要安装你的谷歌驱动器:

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

    我建议您转到笔记本的默认存储库:

    !cd '/gdrive/My Drive/Colab Notebooks/'
    

    实际解决方案

    完成后,您必须刷新和卸载才能查看 Gdrive 中的更改

    drive.flush_and_unmount()
    

    只需下载

    也可以直接使用files下载:

    from google.colab import files
    files.download('sequences.fasta')
    

    【讨论】:

      猜你喜欢
      • 2018-08-15
      • 2018-04-23
      • 2018-10-14
      • 2019-04-20
      • 1970-01-01
      • 2018-08-25
      • 2020-01-01
      • 2019-05-10
      相关资源
      最近更新 更多