[IPython-dev] splitting a class definition across cells in notebook

Aaron Meurer asmeurer at gmail.com
Thu Oct 17 12:47:14 EDT 2013

You could just do it the old fashioned way and use comments.

If you care about markdown formatting, what I would do is do the whole
thing in a markdown cell, with the code of the class in different code
blocks, and then define the actual thing in a code cell at the very end (or
before the markdown cell if that flows better).

Defining the class ad hoc as other people have suggested is only going to
make your complicated class even harder to understand, especially if your
audience doesn't fully understand how methods bind to classes in python.

Aaron Meurer

On Oct 17, 2013, at 8:13 AM, Thomas Kluyver <takowl at gmail.com> wrote:

On 17 October 2013 02:35, Felix Breuer <felix at fbreuer.de> wrote:

> I am working on an IPython notebook in which I want to explain the
> definition of a class in detail. (Think literate programming.) In
> particular, I want to interleave the definition of the individual methods
> of a class with Markdown cells explaining in detail what is going on.
> However, as far as I have been able to find out, I have to put the entire
> class definition in a single cell - and there is no way to amend this
> definition later on. Is there any way around this?

One rough way to do this would be to define each method as a function, and
assign it to the class at the end of its cell. Like this:

def mymethod(self, arg):

MyClass.mymethod = mymethod

That's not ideal, but it should allow you to divide a class up into
separate cells.


IPython-dev mailing list
IPython-dev at scipy.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20131017/8a9c8018/attachment.html>

More information about the IPython-dev mailing list