Allow spyder to run arbitrary .py file until specified line number

27 views
Skip to first unread message

Savin Beniwal

unread,
Sep 9, 2019, 6:13:07 AM9/9/19
to spyder
Dear All

I would like to attract your attention to my query. The query is as follows.

I have written a code of more than 200 lines for my cosmology problem. Every time, I have to run some lines of this code rather than full code. For this, Usually, I select these lines and run using F9.  Unfortunately, Now I'm exhausted from this process. I would like to know some other way to do the same thing, if any.

Is the following one of the possible way to do above work?
--When I run full file or press F5, so before executing full code, the console would ask me from which line number to which line number would you like to run python file? Then console will run only python lines between the user's defined line number. 
It is just my thought, I'm sorry for spyder/python this process may be pointless. I'm also sorry If couldn't my point clearly. Please let me know.

I'm eagerly waiting for your reply.

With Regards!!!


Devidas Kushnure

unread,
Sep 9, 2019, 6:20:42 AM9/9/19
to spyd...@googlegroups.com
Hi Savin Bansal,
you can modify ur code and use 
except and try keywords of python to run a particular block of code.
Hope this will help you.


--
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 view this discussion on the web visit https://groups.google.com/d/msgid/spyderlib/2c6f9041-b306-425a-afdb-54a60a7a34c5%40googlegroups.com.

bcolsen

unread,
Sep 17, 2019, 4:51:33 PM9/17/19
to spyder
For this I use sys.exit() on the line that I want to stop execution at. After that I use code cells #%% to make my visualization from the data

Fábio Casagrande Hirono

unread,
Sep 17, 2019, 4:52:15 PM9/17/19
to spyder
Hi Savin,

Have you tried using cells? You can break your script in cells by adding the special comment "#%%" at the beginning of a line. The cell where the cursor is currently positioned is considered the 'active' cell, and you can run it with "CTRL+ENTER".


Kind Regards,
Fabio

Savin Beniwal

unread,
Sep 18, 2019, 5:27:43 AM9/18/19
to spyder
Hey Fabio

Yes, you're absolutely correct. Recently, I started to work with the same. Honestly, this is what I was waiting for.

Thank you, Fabio, for your reply.
Reply all
Reply to author
Forward
0 new messages