在colaboratory中导入自己的模块后,如何使用?

After import my own module in colaboratory, how can i use it?

这个例子我已经看过了

https://colab.research.google.com/drive/1uvHuizCBqFgvbCwEhK7FvU8JW0AfxgJw

但是,当我抓取 .py 文件时,它 return 一个 JSON 文件。

enter image description here

这个test.py就好了。

def a(x,y):
  z = x + y
  return z

而且我无法使用该模块。

您的图片表明您将标题为 "test.py" 的 笔记本 保存到 Google 驱动器中,因此预计它是 JSON 文件(笔记本存储为 JSON)。我怀疑你真正想做的更像是:

%%writefile test.py
def a(x, y):
  z = x + y
  return z

写一个 plain-text 文件。

您的 import test 成功的原因是存在一个同名的 standard-library 模块 (https://docs.python.org/2/library/test.html#module-test)。我建议您为 .py 文件使用不同的名称来消除歧义:)