How to create python classes in Jupyter Notebook

23,738

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 were you want to use it.

Share:
23,738
Nebi M Aydin
Author by

Nebi M Aydin

Updated on May 07, 2020

Comments

  • Nebi M Aydin
    Nebi M Aydin almost 4 years

    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?