choose python version for @file

17 views
Skip to first unread message

Matt Wilkie

unread,
Feb 2, 2011, 3:12:46 PM2/2/11
to leo-e...@googlegroups.com
When I run Leo from within py3, but am writing a script for python
2.6 the log pane issues syntax errors only applicable to py3:
{{{
Syntax error in: @file xxx.py
19:
20: before = gp.ListFields(fc)
21: after = get_dissolve_fields(fc)
22:* print 'before:\t', before
^
23: print 'after:\t', after
24:
}}}

Is there an @ command to set the language syntax version? If not,
should there be? I can see arguments for and against.

A natural extension would be to want to use the same mechanism to pick
which interpreter (and environment and...) is fired when [ctrl-B] is
pressed. I can see how this could be tricky work to implement cleanly,
also very cool though. I'd love to be able to execute and test batch
scripts with the same ease as I can currently with python from inside
Leo.


--
-matt

Anne

unread,
Feb 3, 2011, 9:37:33 PM2/3/11
to leo-editor
I'm just at the install stage for leo and a newbie to python as well,
but I'm interested in the answer to this.

Is there a python command to set the version?
I don't know of one. I had problems where my scripts (non-leo) were
expecting a different python version than what I had, and I didn't
find a good solution. I think python expects only one installed
version on the system.

Based on what I know, I would expect this is a python issue, not
anything leo could fix.

Ville M. Vainio

unread,
Feb 4, 2011, 1:56:37 AM2/4/11
to leo-e...@googlegroups.com
On Fri, Feb 4, 2011 at 4:37 AM, Anne <cqc...@yahoo.com> wrote:

> Is there a python command to set the version?
> I don't know of one. I had problems where my scripts (non-leo) were
> expecting a different python version than what I had, and I didn't
> find a good solution. I think python expects only one installed
> version on the system.

Typically, you specify the full path to python executable when
launching scripts, if you want to use a specific version.

On Linux, you often have the binaries with full name available (e.g.
'python2.6 test.py')

--
Ville M. Vainio @@ Forum Nokia

Kent Tenney

unread,
Feb 4, 2011, 9:22:26 AM2/4/11
to leo-e...@googlegroups.com
I've had endless problems with interpreter versioning, leading me to:

class Runwith:
def __init__(self, interpreter, code,
cleanup=True, autorun=True,)
def _prepare_run
def _normalize_code
def run
def _report
def _cleanup

it writes a file to disk, makes it executable, runs it, captures
exitcode, err and output, removes the files, provides reports.

This provides complete decoupling from Leo.

I have run-bash and run-python buttons in Leo which run the node
contents as shell or python.

I'm liking it a lot.

I'm currently extending it to provide command line sugar:

$ rw ln -s /home/ktenney/work/src/project/bin/myscript
/home/ktenney/bin --makelink.sh--

The "rw" script executes the command, and creates the script makelink.sh

> --
> You received this message because you are subscribed to the Google Groups "leo-editor" group.
> To post to this group, send email to leo-e...@googlegroups.com.
> To unsubscribe from this group, send email to leo-editor+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/leo-editor?hl=en.
>
>

Edward K. Ream

unread,
May 18, 2011, 10:26:52 AM5/18/11
to leo-e...@googlegroups.com
On Fri, Feb 4, 2011 at 8:22 AM, Kent Tenney <kte...@gmail.com> wrote:
> I've had endless problems with interpreter versioning, leading me to:
>
> class Runwith:
>    def __init__(self, interpreter, code,
>                 cleanup=True, autorun=True,)
>   def _prepare_run
>   def _normalize_code
>   def run
>   def _report
>   def _cleanup
>
> it writes a file to disk, makes it executable, runs it, captures
> exitcode, err and output, removes the files, provides reports.
>
> This provides complete decoupling from Leo.

Sounds like a great solution. Could you send me the code? I'd like
to make it a part of Leo's docs, and put it somewhere like
scripts.leo. Thanks.

Edward

Edward K. Ream

unread,
May 18, 2011, 12:06:32 PM5/18/11
to leo-e...@googlegroups.com
On Wed, May 18, 2011 at 9:26 AM, Edward K. Ream <edre...@gmail.com> wrote:

> Sounds like a great solution.  Could you send me the code?

Kent just sent the code. It's presently in an action item. To be
transferred asap to one or more places, including contrib branch.

Edward

Reply all
Reply to author
Forward
0 new messages