Incremental code development in Jupyter notebook?

Hello everybody.

I am wondering whether notebooks support what I call an incremental development. I would like to use notebook to document the step-by-step progress of building a class, for example. I would like it to be like this:
Cell 1:

class C:
    def __init__(self, a):
        self.a = a

Now I could demonstrate what I can do with this kind of class, e.g. that if I print it, it does not print a nice string representation. So let’s add a method __str__. This is where it starts to be incremental:
Cell 2:

class C:
    def __str__(self):
        return f'C({self.a})'

I.e., I want to incrementally, sequentially, add methods to the class without redefining the whole class including all the previously defined methods.

Is this possible in any way? (E.g. using the elipsis to signal to the notebook that it should collect and use the definitions of class parts from all the preceding cells?)
Or is there any easy way to do it which I overlook?

So far I was doing this by having those incremental versions of code in separate modules, and importing/printing parts of those at the appropriate places. But when a change is required, it is a nightmare to maintain.

If there is no such solution, what is the right place to file a feature request?

Thanks, Petr

Hi Petr

There is a Stack Overflow question on this matter here that also refers to this issue on the Jupyter notebook repo.


1 Like

@psychemedia, Thanks a lot for these pointers! I can now better see the possible issues when implementing something like this. Must evaluate whether any of the suggested solutions will meet my needs, though.