jupyter split class in multiple cells

jupyter split class in multiple cells

need

When using jupyter notebook and jupyter lab, I encountered a requirement:
when writing a class, if you want to annotate the different functions of the class in Markdown format, you can only write the entire class in one cell, and then write the class above Cell or below cell to comment.

example

insert image description here

solution

Now I want to split the bark function to the cell behind the dog class, and it is still a class function of the dog class, which can be realized by using the library jdc.

jdc library

jdc is a Jupyter magic for dynamically defining classes.
See https://alexhagen.github.io/jdc/ for details.
Installation method: pip install jdc

use

Use statement before the function to be added

%%add_to your_class
def your_function(self, params):
	...

Effect

insert image description here
The effect we want is achieved, so that different cells can be used to annotate class functions separately.

Guess you like

Origin blog.csdn.net/jinniulema/article/details/128822429