[IPython-dev] Re: Changes to Notebook Format

Robert Kern rkern at ucsd.edu
Mon Jul 18 06:17:37 CDT 2005


Tzanko Matev wrote:
> Hi all,
> 
> I would like to suggest a few changes to the ipython-log part of the
> notebook format. I think that the following structure might be better:
> 
> <ipython-log logid="default-log">
> 
> <element id="1">

As a sidenote: conventionally, the "id" attribute on any tag must be 
unique document-wide, so we'll stick with "number" here.

> <input type="normal">
> def foo(x, y):
>     return x + y
> </input>
> </element>
> 
> <element id="2">   
> <input type="normal">
> foo(3, 4)
> </input>
> <output type="normal">
> 7
> </output>
> </element>
> 
> </ipython-log>
> 
> The input tags can have types "normal" and "special" which correspond to
> the tags <input> and <special-input> of the current format. The output
> tags can have types "normal", "stdout", "figure", etc. One input tag can
> have several corresponding output tags with different types.

Every "special" input will also have a "normal" input that keeps the 
transformed-into-valid-Python command, too.

> I think
> that the resulting ElementTree object would be more useful that way. In
> order to parse a file of the current format I need to create its
> corresponding ElementTree object and then I must make my own data
> representation from that object, because searching for tags with XPath
> is slow and with the current format there is no easier way to retrieve
> the text I need. With the proposed format I don't really need another
> internal data rpresentation, which would make my code cleaner.
> 
> Also with the new format we won't really need the id argument which will
> make the format less error-prone.

I think that it's entirely possible that the log might have holes in it. 
"Remove unused log entries" and "Renumber entries to restore contiguity" 
are two different operations. One might want to perform the former but 
not the latter if one references In[NN] or Out[NN].

But that may be something we can worry about later.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the IPython-dev mailing list