I've tried to created and use classes in jupyter notebook. But it seems it doesn't work And I've tried this :
def pxlocal(line, cell):
ip = get_ipython()
ip.run_cell_magic("px", line, cell)
ip.run_cell(cell)
ip.register_magic_function(pxlocal, "cell")
And in different cell:
%%pxlocal
class MyClass(object):
But when I run those two cells it gave me this error:
ERROR:root:Cell magic `%%px` not found.
In [11]:
What am I doing wrong?
Run the notebook by typing jupyter notebook into command line. In the web application that opens, navigate to the folder containing the files you downloaded, and open 'Classes in Python.
To create a new notebook, go to New and select Notebook - Python 2. If you have other Jupyter Notebooks on your system that you want to use, you can click Upload and navigate to that particular file. Notebooks currently running will have a green icon, while non-running ones will be grey.
In order to create a module in Jupyter Lab, first create a new notebook. Rename the notebook (e.g. 'module1. ipynb') and copy paste the code in the notebook. Click 'File', 'Download as' and 'Python'
Jupyter Notebook is an environment that we can use to experiment with Python interactively . It allows you to share live Python code with others .
There is no problem with defining a class in a different cell. Just make sure you define the class in a cell that appears before the cell that uses it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With