1

I am trying to use colab to import a python file and use the files function. For example, my first file has the function:

def test():
  return 'foo'

and when I try to call it in my other file like this:

import test_adt as t

t.test()

I get the error AttributeError: module 'test_adt' has no attribute 'test'

Is there something I'm missing here or is colab currently not capable of doing this?

Edit: it's in the correct directory, when you print(t) it returns:

<module 'test_adt' from '/content/test_adt.py'>

1 Answer 1

1

I tried your example. I ran into the exact same problem, but when I clicked "Restart Runtime", and tried again, it worked. I think you just need to restart the runtime in order to clear the import cache after editing the .py file. (Once it works, you can see the problem more clearly by editing and saving the .py file — changes don't take effect in the notebook until you restart the runtime again.)

FYI here are some related questions, although beware of outdated answers.

Sign up to request clarification or add additional context in comments.

1 Comment

still not working for me. I ended up just using visual studio for now, hopefully I can get this figured out soon. Thanks for your reply

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.