Importing Python Notebooks/Files Fails
See original GitHub issueBug report for Colab: http://colab.research.google.com/.
- Describe the current behavior:
When importing another colab notebook file the following errors are returned (the bug is due to improper capitalization in module data for values such as true and null–the first letter of true should be capitalized, while null should be replaced by None or NotImplemented, maybe):
- For notebooks with the private outputs setting disabled (issue at “execution_count”:null):
NameError Traceback (most recent call last) <ipython-input-2-e5202152c002> in <module>() 1 true = True 2 print(sys.path) ----> 3 from Hi import hi as hihi
/content/drive/My Drive/Colab Notebooks/Hi.py in <module>() ----> 1 {“nbformat”:4,“nbformat_minor”:0,“metadata”:{“colab”:{“name”:“Hi.py”,“provenance”:[],“collapsed_sections”:[],“authorship_tag”:“ABX9TyMP9MRH+DF9eO52boVUemSM”},“kernelspec”:{“name”:“python3”,“display_name”:“Python 3”}},“cells”:[{“cell_type”:“code”,“metadata”:{“id”:“tCywtH2Fa-1v”,“colab_type”:“code”,“colab”:{},“cellView”:“both”},“source”:[“def hi():\n”," print("Hi")"],“execution_count”:null,“outputs”:[]}]}…
NameError: name ‘null’ is not defined
- For notebooks with the private outputs setting enabled (issue at “private_outputs”:true):
NameError Traceback (most recent call last) <ipython-input-4-e5202152c002> in <module>() 1 true = True 2 print(sys.path) ----> 3 from Hi import hi as hihi
/content/drive/My Drive/Colab Notebooks/Hi.py in <module>() ----> 1 {“nbformat”:4,“nbformat_minor”:0,“metadata”:{“colab”:{“name”:“Hi.py”,“provenance”:[],“private_outputs”:true,“collapsed_sections”:[],“authorship_tag”:“ABX9TyMP9MRH+DF9eO52boVUemSM”},“kernelspec”:{“name”:“python3”,“display_name”:“Python 3”}},“cells”:[{“cell_type”:“code”,“metadata”:{“id”:“tCywtH2Fa-1v”,“colab_type”:“code”,“colab”:{},“cellView”:“both”},“source”:[“def hi():\n”," print("Hi")"],“execution_count”:null,“outputs”:[0;34…
NameError: name ‘true’ is not defined
- Describe the expected behavior:
The import should work without error. The module properties should be capitalized/named according to the appropriate corresponding Python constants during the import process to resolve the existing errors.
- The web browser you are using (Chrome, Firefox, Safari, etc.):
Chrome
- Link (not screenshot!) to a minimal, public, self-contained notebook that reproduces this issue (click the Share button, then Get Shareable Link):
Hi.py (tried both with private outputs enabled and with private outputs disabled):
def hi():
print("Hi")
TestImporter.ipynb
import sys
if not 'drive/My Drive/Colab Notebooks/' in sys.path:
sys.path.append('drive/My Drive/Colab Notebooks/')
from Hi import hi as hihi
hihi.hi()
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Yup, I downloaded it, deleted the copy on G Drive, and re-uploaded, and it was recognized as a python file and worked correctly afterwards. Thanks!
No, changing the file name will have no effect on the contents.
You can use
File
->Download .py
to save a notebook file as a .py file from the colab UI.