What I am trying to do is to define a function in a custom module on Google Colab.
I created a *.py file to define the function. It is
Then I created a *.ipynb file at the same folder. It is
In myfunc.py, the code is
def somefunc(a) return a*2
In test.ipynb, the code is
cd /content/gdrive/My Drive/Colab import myfunc myfunc.somefunc(2)
Then it occurs error “AttributeError: module ‘myfunc’ has no attribute ‘somefunc'”
I also used
in test.ipynb, which shows
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__']
My function ‘somefunc’ is not in the attributes!!!
This problem only occurs on Colab. I tried it on my computer and an online Jupyter notebooks. They are both working correctly.
PS: No matter whether I put an empty
__init__.py file in the same folder or not, the problem always exists.