[IPython-dev] Re: Changes to Notebook Format

Robert Kern rkern at ucsd.edu
Mon Jul 18 09:20:50 EDT 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">
> <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.

In trying to convert some code to this scheme, I'm finding that it's 
rather cumbersome. Since the number is attached to the ancestor of 
<input> and <output>, I can't just get all normal inputs or all special 
inputs. Nor can I easily tell when a an particular entry also has a 
special input. For example, when I want to export the plain code, I used 
to use a single XPath expression to get all normal inputs and another 
XPath expression to all special inputs, which I stick in a dictionary 
keyed by the number. Then I go through the normal inputs and replace 
them with the special inputs if they are in the dictionary. With the 
above scheme, I iterate over the <cell> elements (I changed <element> to 
<cell>), check for the presence of a special input with an XPath 
expression, use it if found or if not, then I get the normal input with 
an XPath expression. That's not ideal.

Can you describe the operations that you need to do? How often do you 
have to access this data such that XPath is observably too slow? I think 
it's probable that this rearrangement may *increase* the number of XPath 
expressions you need to evaluate.

-- 
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