Leo + Python: the ultimate scripting tool #1

Edward K. Ream edreamleo at charter.net
Sat Nov 8 11:16:14 EST 2003


Reasons why Leo and Python work so well together:

1. You can execute Python scripts directly from anywhere in a Leo outline.

The body text of any node in Leo outline may contain any Python script.  The
Execute Script commands executes this script in a pristine environment.
However, it is trivial to get access, _from within any script_, to all the
data in the present outline.  For example: the following script prints all
the headlines in the outline in which the script is embedded.

from leoGlobals import c # Get access to all data in the present outline.
c = top() # Get the "commander" associated with the topmost outline.
v = c.rootVnode() # Get the root node of the outline.
while v:
..print v.headString()
..v.threadNext() # Move to the next node in "threading" order.

For that matter, scripts can access any data anywhere on your hard drive, or
all the data available on the web, for that matter.  You knew that, of
course, but this "innocent" fact will be important later.

As a result, it becomes very easy to experiment with new scripts from within
Leo.

Edward
--------------------------------------------------------------------
Edward K. Ream   email:  edreamleo at charter.net
Leo: Literate Editor with Outlines
Leo: http://webpages.charter.net/edreamleo/front.html
--------------------------------------------------------------------






More information about the Python-list mailing list