Re: cell execution inbetween ## delimters

112 views
Skip to first unread message
Message has been deleted

David

unread,
Dec 20, 2012, 1:24:09 AM12/20/12
to spyd...@googlegroups.com
If you select the region of code you want to run, then press F9, it will be executed.

I believe this was done in response to previous requests for a cell mode in spyder, and should be good enough for most purposes. If you really need cell mode for python code, then consider using the IPython notebook (http://ipython.org/)

On Tuesday, 18 December 2012 07:46:47 UTC+11, Mark Dean wrote:
Dear all,

Is there any way to get spyder to execute code in blocks marked off by a delimiter. For example a double quote ##?

Thanks a lot,
Mark


Sylvain Corlay

unread,
Mar 2, 2013, 9:49:29 PM3/2/13
to spyd...@googlegroups.com
Hi, 

I think that Mark's proposal is interesting. One could give the choice between delimiters "##" and "# <codecell>" which is the default delimiter when exporting an ipython notebook as a python script. 

Sylvain

Sylvain Corlay

unread,
Mar 3, 2013, 12:03:55 AM3/3/13
to spyd...@googlegroups.com
A very short change that does it in spyderlib/widgets/sourcecode/mixins.py, from line 186: 

        def _is_separator(cursor):
            cursor0 = QTextCursor(cursor)
            cursor0.select(QTextCursor.BlockUnderCursor)
-            text = unicode(cursor0.selectedText())
-            return len(text.strip()) == 0 or text.lstrip()[0] == '#'
+           text = unicode(cursor0.selectedText()).lstrip()
+           return text[:2] == '##' or text[:12] == '# <codecell>'

What do you think of it?
S. 

Sylvain Corlay

unread,
Mar 3, 2013, 11:36:37 AM3/3/13
to spyd...@googlegroups.com
Opened issue 1292 regarding this. 

Sylvain

Carlos Córdoba

unread,
Mar 3, 2013, 9:17:17 PM3/3/13
to spyd...@googlegroups.com
I've been thinking to use

# %%

instead of

##

as cell markers, for two reasons:

1. It'd be far more easier to parse.

2. We could combine them with IPython cell magics, like this:

# %%timeit
print 'foo'

Cheers,
Carlos

El 03/03/13 11:36, Sylvain Corlay escribió:
--
You received this message because you are subscribed to the Google Groups "spyder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spyderlib+...@googlegroups.com.
To post to this group, send email to spyd...@googlegroups.com.
Visit this group at http://groups.google.com/group/spyderlib?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Sylvain Corlay

unread,
Mar 3, 2013, 9:50:52 PM3/3/13
to spyd...@googlegroups.com
However, it can be interesting to keep the "# <codecell>" delimiter as it is the standard delimiter when exporting from an ipython notebook.
S. 

Carlos Córdoba

unread,
Mar 3, 2013, 10:21:03 PM3/3/13
to spyd...@googlegroups.com
Yeah, that would be fine too, but no '##', that would be a nightmare to make it work right :-)

Cheers,
Carlos

El 03/03/13 21:50, Sylvain Corlay escribió:

Sylvain Corlay

unread,
Apr 4, 2013, 11:53:38 AM4/4/13
to spyd...@googlegroups.com
Absolutely. Another argument against '##' is that PEP 8 recommend that inline comment should start with # and a single space. 
Editor such as Eclipse will break all '##' into '# #'... http://www.python.org/dev/peps/pep-0008/
Best,
Sylvain
Reply all
Reply to author
Forward
0 new messages