Comments (5)
A simpler solution that I would be 100% happy with would be just to ignore magics. Currently I get:
File "<unknown>", line 15
%matplotlib inline
^
SyntaxError: invalid syntax
from ipynb.
I would also like to just ignore magic commands. Usually I only use %matplotlib inline
and %timeit
.
from ipynb.
In my use case I only want to import function definitions. I would prefer that all other code cells be skipped
I am happy to define my functions in separated cells to make it easier for the parser
I use %matplotlib and %timeit a lot.
from ipynb.
I also get the same error when using "!"
for example: "!pip"
from ipynb.
So this isn't a direct solution but maybe a step forward. Since magics are usually applied at the "cell" level it might be worth considering importing "cells" instead of just functions. If that's the case then you can use something like this
from IPython.lib.kernel import get_connection_file
from jupyter_client import BlockingKernelClient
def import_cell(notebook_path, cell_number):
## Read notebook
notebook_file = open(notebook_path)
nb = nbformat.read(notebook_file,as_version=4)
## Creat kernel client on current
## running kernal
client = BlockingKernelClient()
client.load_connection_file(get_connection_file())
client.start_channels()
## Execute code cell
nb_code_cells = [c for c in nb.cells if c["cell_type"] == "code"]
client.execute(code_cells[cell_number].source)
import_cell("path/to/notebook.ipynb", 0)
To "import" (really it just executes the cell in your current ipython kernel). But if users want to import cells by cell tag they could do something like
from ipynb.fs.cells.my_notebook import my_cell_tag
Where the cell tag could be searched for in the metadata across the notebook
from ipynb.
Related Issues (20)
- TypeError that occurs in IPython notebook but not IPython shell HOT 4
- IndentationError: unexpected indent HOT 7
- can not import functions that have doc string in them
- AttributeError: 'Tuple' object has no attribute 'id' HOT 1
- Fails on image ref in markdown
- ipynb.fs.defs raise error if there is subscript line HOT 2
- AttributeError in _filter_ast_node HOT 1
- Reload semantics HOT 3
- __package__ = None
- %matplotlib in the source notebook causes error HOT 2
- Encoding errors
- Better API ergonomics
- Import importnb to this project HOT 5
- import error
- incorrect version or language HOT 8
- How to import the ipynb file that is in a different folder HOT 2
- use symbolic link notebook
- Load ipynb contained from a different directory HOT 2
- Colab setup HOT 1
- importing .ipynb notebooks in Sagemath 9.4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ipynb.