class NotebookLoader(object): """Module Loader for Jupyter Notebooks""" def __init__(self, path=None): self.shell = InteractiveShell.instance() self.path = path def load_module(self, fullname): """import a notebook as a module""" path = find_notebook(fullname, self.path) print ("importing Jupyter notebook from %s" % path) # load the notebook object with io.open(path, 'r', encoding='utf-8') as f: nb = read(f, 4) # create the module and add it to sys.modules # if name in sys.modules: # return sys.modules[name] mod = types.ModuleType(fullname) mod.__file__ = path mod.__loader__ = self mod.__dict__['get_ipython'] = get_ipython sys.modules[fullname] = mod # extra work to ensure that magics that would affect the user_ns # actually affect the notebook module's ns save_user_ns = self.shell.user_ns self.shell.user_ns = mod.__dict__ try: for cell in nb.cells: if cell.cell_type == 'code': # transform the input to executable Python code = self.shell.input_transformer_manager.transform_cell(cell.source) # run the code in themodule exec(code, mod.__dict__) finally: self.shell.user_ns = save_user_ns return mod
File "<unknown>", line 13
"""uses Gauss's method for summing integers http://wmueller.com/precalculus/advanced/hint4_3_6.html"""
^
IndentationError: unexpected indent
2) I needed to use import 'as'. I think the https://github.com/ipython/ipynb readme.md needs to be update.
Here is an example
import ipynb.fs.defs.myMathFunctions as mmf
mmf.quickSum(5)
many thanks--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-14-2eb451ec0e6d> in <module>() ----> 1 from ipynb.fs.defs.week1 import patternToNumber 2 #import ipynb.fs.defs.week1 as wk1 3 4 #import ipynb.fs.defs.week1 as week1 5 # import ipynb.fs from .defs.week2 \ /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py in _find_and_load(name, import_) /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_) /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py in _load_unlocked(spec) /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap_external.py in exec_module(self, module) /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ipynb/fs/defs/__init__.py in get_code(self, fullname) 60 )) 61 return self.source_to_code( ---> 62 self._get_filtered_ast(code_from_ipynb(nb)), 63 self.path 64 ) /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ipynb/fs/defs/__init__.py in _get_filtered_ast(self, source) 47 """ 48 tree = ast.parse(source) ---> 49 tree.body = [n for n in tree.body if self._filter_ast_node(n)] 50 return tree 51 /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ipynb/fs/defs/__init__.py in <listcomp>(.0) 47 """ 48 tree = ast.parse(source) ---> 49 tree.body = [n for n in tree.body if self._filter_ast_node(n)] 50 return tree 51 /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ipynb/fs/defs/__init__.py in _filter_ast_node(self, node) 38 39 if isinstance(node, ast.Assign): ---> 40 return all([t.id.isupper() for t in node.targets]) 41 42 return False /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ipynb/fs/defs/__init__.py in <listcomp>(.0) 38 39 if isinstance(node, ast.Assign): ---> 40 return all([t.id.isupper() for t in node.targets]) 41 42 return False AttributeError: 'Tuple' object has no attribute 'id'
Hi MatthiasI am a total newbie how do I report a bug? D
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/CANJQusUDLjR83GqX1UtxqUoHO_GxkWoB3nzPWQMnnBCXPVF3ag%40mail.gmail.com.