[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

ILeo (IPython-Leo bridge); a marriage made in heaven?

vivainio@gmail.com

2/22/2008 7:34:00 PM

Here is something cool that will rock your world (ok, excuse the
slight hyperbole):

Introduction
============

The purpose of ILeo, or leo-ipython bridge, is being a two-way
communication
channel between Leo and IPython. The level of integration is much
deeper than
conventional integration in IDEs; most notably, you are able to store
*data* in
Leo nodes, in addition to mere program code. The possibilities of this
are
endless, and this degree of integration has not been seen previously
in the python
world.

IPython users are accustomed to using things like %edit to produce non-
trivial
functions/classes (i.e. something that they don't want to enter
directly on the
interactive prompt, but creating a proper script/module involves too
much
overhead). In ILeo, this task consists just going to the Leo window,
creating a node
and writing the code there, and pressing alt+I (push-to-ipython).

Obviously, you can save the Leo document as usual - this is a great
advantage
of ILeo over using %edit, you can save your experimental scripts all
at one
time, without having to organize them into script/module files (before
you
really want to, of course!)


Installation
============

You need at least Leo 4.4.7, and the development version of IPython
(ILeo
will be incorporated to IPython 0.8.3).

You can get IPython from Launchpad by installing bzr and doing

bzr branch lp:ipython

and running "setup.py install".

You need to enable the 'ipython.py' plugin in Leo:

- Help -> Open LeoSettings.leo

- Edit @settings-->Plugins-->@enabled-plugins, add/uncomment
'ipython.py'

- Restart Leo. Be sure that you have the console window open (start
leo.py from console, or double-click leo.py on windows)

- Press alt+5 OR alt-x start-ipython to launch IPython in the console
that
started leo. You can start entering IPython commands normally, and Leo
will keep
running at the same time.

Accessing IPython from Leo
==========================

IPython code
------------

Just enter IPython commands on a Leo node and press alt-I to execute
push-to-ipython to execute the script in IPython. 'commands' is
interpreted
loosely here - you can enter function and class definitions, in
addition to the
things you would usually enter at IPython prompt - calculations,
system commands etc.

Everything that would be legal to enter on IPython prompt is legal to
execute
from ILeo.

Results will be shows in Leo log window for convenience, in addition
to the console.

Suppose that a node had the following contents:
{{{
1+2
print "hello"
3+4

def f(x):
return x.upper()

f('hello world')
}}}

If you press alt+I on that done, you will see the following in Leo log
window (IPython tab):

{{{
In: 1+2
<2> 3
In: 3+4
<4> 7
In: f('hello world')
<6> 'HELLO WORLD'
}}}

(numbers like <6> mean IPython output history indices).


Plain Python code
-----------------

If the headline of the node ends with capital P, alt-I will not run
the code
through IPython translation mechanism but use the direct python 'exec'
statement
(in IPython user namespace) to execute the code. It wont be shown in
IPython
history, and sometimes it is safer (and more efficient) to execute
things as
plain Python statements. Large class definitions are good candidates
for P
nodes.

Accessing Leo nodes from IPython
================================

The real fun starts when you start entering text to leo nodes, and are
using
that as data (input/output) for your IPython work.

Accessing Leo nodes happens through the variable 'wb' (short for
"WorkBook")
that exist in the IPython user namespace. Nodes that are directly
accessible are
the ones that have simple names which could also be Python variable
names;
'foo_1' will be accessible directly from IPython, whereas 'my scripts'
will not.
If you want to access a node with arbitrary headline, add a child node
'@a foo'
(@a stands for 'anchor'). Then, the parent of '@a foo' is accessible
through
'wb.foo'.

You can see what nodes are accessible be entering (in IPython)
wb.<TAB>. Example:

[C:leo/src]|12> wb.
wb.b wb.tempfile wb.rfile wb.NewHeadline
wb.bar wb.Docs wb.strlist wb.csvr

Suppose that we had a node with headline 'spam' and body:

['12',2222+32]

we can access it from IPython (or from scripts entered into other Leo
nodes!) by doing:

C:leo/src]|19> wb.spam.v
<19> ['12', 2254]

'v' attribute stands for 'value', which means the node contents will
be run
through 'eval' and everything you would be able to enter into IPython
prompt
will be converted to objects. This mechanism can be extended far
beyond direct
evaluation (see '@cl definitions').

'v' attribute also has a setter, i.e. you can do:

wb.spam.v = "mystring"

Which will result in the node 'spam' having the following text:

'mystring'

What assignment to 'v' does can be configured through generic
functions
(simplegeneric module, will be explained later).

Besides v, you can set the body text directly through wb.spam.b =
"some\nstring", headline by wb.spam.h = 'new_headline' (obviously you
must
access the node through wb.new_headline from that point onwards), and
access the
contents as string list (IPython SList) through 'wb.spam.l'.

If you do 'wb.foo.v = 12' when node named 'foo' does not exist, the
node titled
'foo' will be automatically created and assigned body 12.

@cl definitions
===============

If the first line in the body text is of the form '@cl sometext',
IPython will
will evaluate 'sometext' and call the result with the rest of the body
when you
do 'wb.foo.v'. An example is in place here. Suppose that we have
defined a class
(I use the term class in a non-python sense here)

{{{
def rfile(body,n):
""" @cl rfile

produces a StringIO (file like obj) of the rest of the body """

import StringIO
return StringIO.StringIO(body)
}}}

Now, let's say you node 'spam' with text

{{{
@cl rfile
hello
world
and whatever
}}}

Now, on IPython, we can do this:

{{{
[C:leo/src]|22> f = wb.spam.v
[C:leo/src]|23> f
<23> <StringIO.StringIO instance at 0x04E7E490>
[C:leo/src]|24> f.readline()
<24> u'hello\n'
[C:leo/src]|25> f.readline()
<25> u'world\n'
[C:leo/src]|26> f.readline()
<26> u'and whatever'
[C:leo/src]|27> f.readline()
<27> u''
}}}

You should declare new @cl types to make ILeo as convenient your
problem domain as possible. For example, a "@cl etree" could return
the elementtree object for xml content, or

Special node types
==================

@ipy-startup
------------

If this node exist, the *direct children* of this will be pushed to
IPython when
ILeo is started (you press alt+5). Use it to push your own @cl
definitions etc.
The contents of of the node itself will be ignored.

@ipy-results
------------

When you create a new node (wb.foo.v = 'stuff'), the node foo will be
created as
a child of this node. If @ipy-results does not exist, the new node
will be created after the currently selected node.

@a nodes
--------

You can attach these as children of existing nodes to provide a way to
access
nodes with arbitrary headlines, or to provide aliases to other nodes.
If
multiple @a nodes are attached as children of a node, all the names
can be used
to access the same object.

Acknowledgements & History
==========================

This idea got started when I (Ville) saw this post by Edward Ream (the
author of
Leo) on IPython developer mailing list:

http://lists.ipython.scipy.org/pipermail/ipython-dev/2008-January/0...

I was using FreeMind as mind mapping software, and so I had an
immediate use
case for Leo (which, incidentally, is superior to FreeMind as mind
mapper). The
wheels started rolling, I got obsessed with the power of this concept
(everything clicked together), and Edwards excitement paralleled mine.
Everything was mind-bogglingly easy/trivial, something that is typical
of all
revolutionary technologies (think Python here).

The discussion that "built" ILeo is here:
http://sourceforge.net/forum/forum.php?thread_id=1911662&foru...

10 Answers

Edward K. Ream

2/23/2008 2:34:00 PM

0

> Here is something cool that will rock your world (ok, excuse the slight
> hyperbole):

Many thanks for this posting, Ville. It is indeed very cool:

- It shows how Leo can be used *now* as an IPython notebook.

- It expands the notion of what is possible with Leo/IPython/Python scripts.

Your ideas are destined to be of great importance to both the IPython and
Leo communities.
I shall continue this discussion at:

http://groups.google.com/group/leo-editor/browse_thread/thread/3747a1...

Edward
--------------------------------------------------------------------
Edward K. Ream email: edreamleo@yahoo.com
Leo: http://webpages.charter.net/edreamleo/...
--------------------------------------------------------------------


Ricardo Aráoz

2/23/2008 8:54:00 PM

0

Edward K Ream wrote:
>> Here is something cool that will rock your world (ok, excuse the slight
>> hyperbole):
>
> Many thanks for this posting, Ville. It is indeed very cool:
>
> - It shows how Leo can be used *now* as an IPython notebook.
>
> - It expands the notion of what is possible with Leo/IPython/Python scripts.
>
> Your ideas are destined to be of great importance to both the IPython and
> Leo communities.
> I shall continue this discussion at:
>
> http://groups.google.com/group/leo-editor/browse_thread/thread/3747a1...
>
> Edward
> --------------------------------------------------------------------
> Edward K. Ream email: edreamleo@yahoo.com
> Leo: http://webpages.charter.net/edreamleo/...
> --------------------------------------------------------------------
>
>

Are you part of Leo? This smells like a marketing scheme to me.





vivainio@gmail.com

2/23/2008 9:50:00 PM

0

On Feb 23, 10:54 pm, Ricardo Aráoz <ricar...@gmail.com> wrote:

> Are you part of Leo? This smells like a marketing scheme to me.

Yes, Edward is part of Leo and I am part of IPython. In fact, most of
my income comes from selling IPython T-shirts at the local flea market
and I therefore have to resort to shady operations like this to pump
up my fading income. Hey, it pays the bills!

Seriously, though; this *is* cool stuff. I have an updated version of
the document here: http://vvtools.googlecode.com/files/IL...

shakeeb.alireza

2/24/2008 1:02:00 PM

0

> Are you part of Leo? This smells like a marketing scheme to me.

Actually this is an example of a beautiful collaboration between
Edward (the progenitor of leo) and Ville (the ipython side).

Fantastic and elegant stuff, which you have to try to appreciate.

AK

William Black

6/18/2014 3:59:00 PM

0

On Wed, 18 Jun 2014 10:33:20 -0400, "Don Phillipson"
<e925@SPAMBLOCK.ncf.ca> wrote:

>) Had the wily Japanese merely descended
>on the Netherlands Indies and British SE Asia (bypassing the
>Phillippines and agreeing with Vichy France by negotiation) it is
>hard to see why the USA should act against Japan, let alone
>Germany as well. The Japanese Empire might then have lasted
>much longer, and the British a bit less than it did: but this is no
>case that the UK could alone "conquer" Germany.

The Japanese really need a general European war in which the British
are doing badly.

If the Germans come unglued at any point then any Japanese aggression
is probably an unfeasible gamble.

Alfred Montestruc

7/5/2014 2:54:00 AM

0

On Wednesday, June 18, 2014 10:59:13 AM UTC-5, Bill wrote:
> On Wed, 18 Jun 2014 10:33:20 -0400, "Don Phillipson"
>
> <e925@SPAMBLOCK.ncf.ca> wrote:
>
>
>
> >) Had the wily Japanese merely descended
>
> >on the Netherlands Indies and British SE Asia (bypassing the
>
> >Phillippines and agreeing with Vichy France by negotiation) it is
>
> >hard to see why the USA should act against Japan, let alone
>
> >Germany as well. The Japanese Empire might then have lasted
>
> >much longer, and the British a bit less than it did: but this is no
>
> >case that the UK could alone "conquer" Germany.
>
>
>
> The Japanese really need a general European war in which the British
>
> are doing badly.


OTL until the USA entered WWII on the British side. Or did you forget the the Germans chased the British off the European mainland and defeated & occupied France?


>
>
> If the Germans come unglued at any point then any Japanese aggression
>
> is probably an unfeasible gamble.

No the more accurate statement is if the USA decides to get involved in the fight, Japan is going to be in deep trouble.

The critical issue is keeping Roosevelt out of the fight.

Obligatory what if; the Japanese government hires a lot of US private investigators and dredges through the Roosevelt family's dirty laundry (and other figures in the FDR administration), , , and dumps all findings into the American press broadly in many newspapers at the same time with photographic evidence, say starting in 1936, and does not stop, till Roosevelt is out of office.

That could keep him too busy to deal with foreign policy.


Anyone reasonably knowledgeable of American history of the era should know that FDR, Elinor Roosevelt, and many of his cabinet officers were very vulnerable to that sort of attack, in the climate of that time.

Larry Headlund

7/5/2014 3:10:00 PM

0

On Friday, July 4, 2014 10:54:22 PM UTC-4, Alfred Montestruc wrote:
> On Wednesday, June 18, 2014 10:59:13 AM UTC-5, Bill wrote:
>
> > On Wed, 18 Jun 2014 10:33:20 -0400, "Don Phillipson"
>
> >
>
> > <e925@SPAMBLOCK.ncf.ca> wrote:
>
> >
>
> >
>
> >
>
> > >) Had the wily Japanese merely descended
>
> >
>
> > >on the Netherlands Indies and British SE Asia (bypassing the
>
> >
>
> > >Phillippines and agreeing with Vichy France by negotiation) it is
>
> >
>
> > >hard to see why the USA should act against Japan, let alone
>
> >
>
> > >Germany as well. The Japanese Empire might then have lasted
>
> >
>
> > >much longer, and the British a bit less than it did: but this is no
>
> >
>
> > >case that the UK could alone "conquer" Germany.
>
> >
>
> >
>
> >
>
> > The Japanese really need a general European war in which the British
>
> >
>
> > are doing badly.
>
>
>
>
>
> OTL until the USA entered WWII on the British side. Or did you forget the the Germans chased the British off the European mainland and defeated & occupied France?
>
>
>
>
>
> >
>
> >
>
> > If the Germans come unglued at any point then any Japanese aggression
>
> >
>
> > is probably an unfeasible gamble.
>
>
>
> No the more accurate statement is if the USA decides to get involved in the fight, Japan is going to be in deep trouble.
>
>
>
> The critical issue is keeping Roosevelt out of the fight.
>
>
>
> Obligatory what if; the Japanese government hires a lot of US private investigators and dredges through the Roosevelt family's dirty laundry (and other figures in the FDR administration), , , and dumps all findings into the American press broadly in many newspapers at the same time with photographic evidence, say starting in 1936, and does not stop, till Roosevelt is out of office.
> That could keep him too busy to deal with foreign policy.
> Anyone reasonably knowledgeable of American history of the era should know that FDR, Elinor Roosevelt, and many of his cabinet officers were very vulnerable to that sort of attack, in the climate of that time.

A Japanese campaign against FDR beginning in 1936 requires
1. Japanese know they are going to be in a prolonged war in China. The Marco Polo Bridge Incident wasn't until July of 1937 and the Japanese could not know how long the war would be.
2. That FDR would be hostile to Japanese policy in China. The Panay incident which was the beginning of souring relations was in December 1937.
3. Expectations of an FDR third term. Nobody in 1936 was expecting this.
4. General European war making it possible for Japan to contemplate the kind of aggression which would make the US an active enemy.
5. Knowledge that an FDR replacement would not be hostile to Japanese interests. Even in the 1930s there was a Republican "China Lobby" with ties to China missionaries like Luce and Americans with business interests in China.

I don't think so.

Alfred Montestruc

7/5/2014 7:04:00 PM

0

On Saturday, July 5, 2014 10:10:11 AM UTC-5, Larry Headlund wrote:
> On Friday, July 4, 2014 10:54:22 PM UTC-4, Alfred Montestruc wrote:
>
> > On Wednesday, June 18, 2014 10:59:13 AM UTC-5, Bill wrote:
>
> >
>
> > > On Wed, 18 Jun 2014 10:33:20 -0400, "Don Phillipson"
>
> >
>
> > >
>
> >
>
> > > <e925@SPAMBLOCK.ncf.ca> wrote:
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > > >) Had the wily Japanese merely descended
>
> >
>
> > >
>
> >
>
> > > >on the Netherlands Indies and British SE Asia (bypassing the
>
> >
>
> > >
>
> >
>
> > > >Phillippines and agreeing with Vichy France by negotiation) it is
>
> >
>
> > >
>
> >
>
> > > >hard to see why the USA should act against Japan, let alone
>
> >
>
> > >
>
> >
>
> > > >Germany as well. The Japanese Empire might then have lasted
>
> >
>
> > >
>
> >
>
> > > >much longer, and the British a bit less than it did: but this is no
>
> >
>
> > >
>
> >
>
> > > >case that the UK could alone "conquer" Germany.
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > > The Japanese really need a general European war in which the British
>
> >
>
> > >
>
> >
>
> > > are doing badly.
>
> >
>
> >
>
> >
>
> >
>
> >
>
> > OTL until the USA entered WWII on the British side. Or did you forget the the Germans chased the British off the European mainland and defeated & occupied France?
>
> >
>
> >
>
> >
>
> >
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > > If the Germans come unglued at any point then any Japanese aggression
>
> >
>
> > >
>
> >
>
> > > is probably an unfeasible gamble.
>
> >
>
> >
>
> >
>
> > No the more accurate statement is if the USA decides to get involved in the fight, Japan is going to be in deep trouble.
>
> >
>
> >
>
> >
>
> > The critical issue is keeping Roosevelt out of the fight.
>
> >
>
> >
>
> >
>
> > Obligatory what if; the Japanese government hires a lot of US private investigators and dredges through the Roosevelt family's dirty laundry (and other figures in the FDR administration), , , and dumps all findings into the American press broadly in many newspapers at the same time with photographic evidence, say starting in 1936, and does not stop, till Roosevelt is out of office.
>
> > That could keep him too busy to deal with foreign policy.
>
> > Anyone reasonably knowledgeable of American history of the era should know that FDR, Elinor Roosevelt, and many of his cabinet officers were very vulnerable to that sort of attack, in the climate of that time.
>
>
>
> A Japanese campaign against FDR beginning in 1936 requires
>
> 1. Japanese know they are going to be in a prolonged war in China. The Marco Polo Bridge Incident wasn't until July of 1937 and the Japanese could not know how long the war would be.


They knew it was possible from a simple study of the logistics.


>
> 2. That FDR would be hostile to Japanese policy in China. The Panay incident which was the beginning of souring relations was in December 1937.

They knew FDR was hostile to the Japanese period. They knew FDR was a racist.

Japan invaded China in 1931 not 1936 and created the Manchurian puppet state Manchuko

http://www.japanfocus.org/-Richard_J_-Smet...

"Crowley's term, the people who led "Japan's quest for autonomy," mostly army officers and so-called "new bureaucrats" and "new zaibatsu," became increasingly powerful in the same half-decade. Military officers plotted and carried out an invasion of Manchuria in September 1931, and their actions met thunderous public applause at home. The mass society that had brought Japan democracy in the 1920s helped bring it something else in the 1930s. The various portents discussed above---latent nationalism, resentment over America's treatment of Japanese immigrants, the increasingly unified British and American resistance to Japanese actions in China, and the suffering of many Japanese during the depression, came together to create a climate of support for the military--the men on horseback, those who had the easy answers--the men who advocated direct action, not weak-kneed (and rational) compromise. From 1931 until 1936, various segments of the military instigated overseas aggression, coup d'état attempts at home, and assassinations that changed the nature of Japan's government and foreign policy. The military killed or silenced the people who advocated cooperation--the threat of assassination was a powerful weapon for keeping opponents in line."

The US Government and the British government were both very hostile to Japan from the invasion of China in Sept 1931 on.

Racism of FDR,

http://en.wikipedia.org/wiki/Criticism_of_Franklin_D._Roosevelt#Accusations...

"A widely believed myth about the 1936 games was that Hitler had snubbed Owens, something that never happened. Owens said, "Hitler didn't snub me--it was [FDR] who snubbed me. The president didn't even send me a telegram." (Triumph, a book about the 1936 Olympics by Jeremy Schaap)"


The Japanese people were treated as inferior undesirables by openly racist US Government policy promoted by FDR. This is most obvious in immigration policy.

To assert the Japanese government "did not know" FDR was a racist and hated them for racist reasons is preposterous.



>
> 3. Expectations of an FDR third term. Nobody in 1936 was expecting this.

Don't be ridiculous. FDR was a power hungry politician who had zero respect for the rule of law.

http://whatreallyhappened.com/WRHARTICLES/pearl/www.geocities.com/Pentagon/631...





>
> 4. General European war making it possible for Japan to contemplate the kind of aggression which would make the US an active enemy.
>


That was obviously coming. Anyone with eyes could see it.



> 5. Knowledge that an FDR replacement would not be hostile to Japanese interests. Even in the 1930s there was a Republican "China Lobby" with ties to China missionaries like Luce and Americans with business interests in China.

They do not need to replace him, they need to distract him with scandals at home that because he is a power-mad politician, he will never voluntarily leave the white-house, he will fight tooth and nail to stay in office and so distract the US from what is going on on the other side of the pacific.



>
>
>
> I don't think so.

You don't seem terribly bright to me.

Bradipus

7/5/2014 11:32:00 PM

0

Alfred Montestruc 04:54, sabato 5 luglio 2014:

> Obligatory what if; the Japanese government hires a lot of US
> private  investigators and dredges through the Roosevelt
> family's dirty laundry (and other figures in the FDR
> administration), , , and dumps all findings into the American
> press broadly in many newspapers at the same time with
> photographic evidence, say starting in 1936, and does not
> stop, till Roosevelt is out of office.
>
> That could keep him too busy to deal with foreign policy.
>
>
> Anyone reasonably knowledgeable of American history of the
> era should know that FDR, Elinor Roosevelt, and many of his
> cabinet officers were very vulnerable to that sort of attack,
> in the climate of that time.


So why Republicans didn't do that?


--
Bradipus

Alfred Montestruc

7/7/2014 2:57:00 AM

0

On Saturday, July 5, 2014 6:32:17 PM UTC-5, Bradipus wrote:
> Alfred Montestruc 04:54, sabato 5 luglio 2014:
>
>
>
> > Obligatory what if; the Japanese government hires a lot of US
>
> > private ?investigators and dredges through the Roosevelt
>
> > family's dirty laundry (and other figures in the FDR
>
> > administration), , , and dumps all findings into the American
>
> > press broadly in many newspapers at the same time with
>
> > photographic evidence, say starting in 1936, and does not
>
> > stop, till Roosevelt is out of office.
>
> >
>
> > That could keep him too busy to deal with foreign policy.
>
> >
>
> >
>
> > Anyone reasonably knowledgeable of American history of the
>
> > era should know that FDR, Elinor Roosevelt, and many of his
>
> > cabinet officers were very vulnerable to that sort of attack,
>
> > in the climate of that time.
>
>
>
>
>
> So why Republicans didn't do that?
>
>
>
>
>
> --
>
> Bradipus

Because they did not know, and such an investigation can backfire on an internal political opponent.

The Japanese could simply deny and hide behind diplomatic immunity. The Japanese would not know either, but had much less to lose.