[IPython-dev] Re: Changes to Notebook Format

Tzanko Matev tsanko at gmail.com
Sat Jul 23 14:44:31 EDT 2005

> Robert Kern wrote:
> > Tzanko Matev wrote:
> >
> >> <element id="1">
> >> <input type="normal">
> >> def foo(x, y):
> >>     return x + y
> >> </input>
> >> </element>
> >
> > 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, 
> hm.
> > 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.
> thanks for writing up this info on needed operations, btw.
> > 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.
> any info on how this is turning out?

I attach my response to Robert Kern, and his response. I must have
missed to cc: my letter to the mailing list for which I'm sorry. Basicly
the idea is that often I will need to find all the outputs that a given
input generates and that was slow with the first implementation because
I had to use XPath to do it.

> BTW, if i may suggest a style issue: the nbshell code seems to include 
> 'getters' that would be naturally properties in current Python (they 
> came already in 2.2 so no version prob.), e.g. these in PythonPluginFactory:
>    def GetString(self):
>         """ Returns the type string of the plugin. This is used when a 
> notebook
>         file is loaded. See notebookformat.txt for more info"""
>         return "python"
>     def GetType(self):
>         """ Returns the way data should be passed to the plugin. Currently
>         supported types are "raw" and "encoded". See notebookformat.txt for
>         more info"""
>         return "raw" #Probably only the python code plugin should be raw
> those are currently unnecessary, but could be just .string and .type (or 
> perhaps .type and .input_type?). then later if they need to wrapped to 
> some method just make them properties ( 
> http://www.python.org/2.2/descrintro.html#property ).
> in one other project i've tried using properties even for something 
> really dynamic, in fact for an exactly similar thing as this in 
> ipnDocument.py:
>     def IsModified(self):
>         """returns if the file has been modified since last save"""
>         #TODO: Right now there is no point in doing anything useful
>         #here. When things are done fix it
>         return True
> there am using a property called 'changed', which has such a getter that 
> it resets the change flag in the object. so this 'IsModified()' might 
> also be better just as a property called 'modified', but that is already 
> a bit more controversial issue (as ppl are perhaps used to such dynamic 
> things being exposed as methods?)

Point taken. I've written a lot of C++ code so I have learned some bad
habits from it :) I changed some of the get/set methods to properties or
variables. A lot of my code was written before it was decided to go with
xml so a lot of unnecessary stuff needs to be cleaned up. Right now, I
will leave it as it is, because there are more important things to do.

-------------- next part --------------
An embedded message was scrubbed...
From: Tzanko Matev <tsanko at gmail.com>
Subject: Re: [IPython-dev] Re: Changes to Notebook Format
Date: Mon, 18 Jul 2005 23:22:16 +0300
Size: 3583
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20050723/abe21f8d/attachment.mht>
-------------- next part --------------
An embedded message was scrubbed...
From: Robert Kern <rkern at ucsd.edu>
Subject: Re: [IPython-dev] Re: Changes to Notebook Format
Date: Mon, 18 Jul 2005 13:54:07 -0700
Size: 6023
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20050723/abe21f8d/attachment-0001.mht>

More information about the IPython-dev mailing list