On 10/22/2013 7:38 PM, Steve Litt wrote:
On Mon, 21 Oct 2013 21:55:26 -0400
gatesphere <gatesph...@gmail.com> wrote:


Keep pushing!  Here's another step-by-step:

1) Create a node, headline named "@file myfile.py" (henceforth "node
A") 2) In the body of that node, put the following:
@language python
<< docstring >>
@others
if __name__ == '__main__':
      main()
3) Create a child node of "node A", headline named "<< docstring >>"
4) In the body of that node, type this:
'''
This is a docstring.  It explains what this python module does.
'''
5) Create a child node of "node A", headline named "main"
6) In the body of that node, type this:
def main():
      print "hello, world!"
7) Save your .leo.  It should create myfile.py automatically.
8) Open myfile.py in an external editor.  Observe the structure. Run
it with a python interpreter if you want to make sure it's valid.
9) Experiment more!
Done. Worked. Made a Python file called myfile.py that did the right
thing and said the right thing in pydoc.

However, I could not run it with Ctrl+B. Is there an either-or choice
between putting it in a file and running it from a Ctrl+B?
No, not at all. But there is a difference between 'print' and 'g.es'. 'print' sends things to the console, so if you're running Leo with a console window, you'd see "hello, world!' there. However, g.es sends things to the log pane. Replace the print line with g.es('hello, world!'), save, and your Ctrl+B on the parent node will work just fine.

Oh, another possible hiccup... python 2 had print as a command, python 3 has it as a function... but that's neither here nor there.

Then I tried having three subnodes, each with a different g.ex(),
and seeing if I could Ctrl+B their parent. No dice. However one does
functional decomposition in Leo, it takes quite a bit of reading to
find out.
Agreed.  A third step-by-step is in order, perhaps?

1) Create a node, headline anything you want.
2) In the body write the following:
@language python

x = 1

@others
3) Create a child node of that node, headline anything you want.
4) In that node's body, write the following:
g.es('test# ', x)
5) Clone that node a few times so that it is it's own sibling (i.e.
hit Ctrl-` with the node selected a few times)
6) Ctrl-B the parent node (from step 1).  Observe the magic!
Done. It printed "Test# 1". But only once.
Strange. I noticed I forgot a line after the g.es portion, namely x += 1. But that shouldn't have skewed the results. Are you sure you had the parent node selected?
So then I added a second
second level node that printed "Steve was here", and sure enough, it
printed both "Steve was here" and "test #1".

It appears to me that Leo won't execute multiple clones.
Attached is a leo outline with the exact script above that I just built and tested, it works as intended. If you can't get it to work with this one, you've hit a bug. We'll investigate that further.

I was able to set x in one node and print it in another. I was able to
increment in consecutive nodes and have it come out right.
That's good.

That example uses clones to show how they can be used to reduce code
repetition.
I was unable to get several clones all execute.
Again, try the attached outline.  Let me know if you can't get it to work.

-->Jake
Thanks,

SteveT

Steve Litt                *  http://www.troubleshooters.com/
Troubleshooting Training  *  Human Performance


--
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/groups/opt_out.
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by Leo (http://leoeditor.com/leo_toc.html) -->
<?xml-stylesheet ekr_test?>
<leo_file xmlns:leo="http://www.leo-editor.org/2011/leo"; >
<leo_header file_format="2" tnodes="0" max_tnode_index="0" clone_windows="0"/>
<globals body_outline_ratio="0.5" body_secondary_ratio="0.5">
	<global_window_position top="50" left="50" height="500" width="700"/>
	<global_log_window_position top="0" left="0" height="0" width="0"/>
</globals>
<preferences/>
<find_panel_settings/>
<vnodes>
<v t="peckj.20131022204243.3696" a="E"><vh>Select this node, and hit Ctrl+B</vh>
<v t="peckj.20131022204243.3697"><vh>DO NOT run this node</vh></v>
<v t="peckj.20131022204243.3697"></v>
<v t="peckj.20131022204243.3697"></v>
<v t="peckj.20131022204243.3697"></v>
</v>
</vnodes>
<tnodes>
<t tx="peckj.20131022204243.3696">@language python

x = 1

@others</t>
<t tx="peckj.20131022204243.3697">g.es('test# ', x)
x += 1</t>
</tnodes>
</leo_file>

Reply via email to