How to run the current line in Sublime Text 2? Or, IDE that allows running the current line in Python

Asked

Viewed 4,059 times

4

In the (IDE to ) it is possible to run the current line instead of the entire file using ctrl (or cmd) + enter. This is very useful for when you want to test just one piece of code separate from the rest of the file.

I recently started using Sublime Text 2 with Python. I know it is possible to run the code directly from Sublime Text 2 with cmd + b (but I first had to adjust the python.sublime-build file so that it could get the correct path).

But it would be nice also to have the option to run only the current line instead of the entire file. It is possible to do this?

If not possible in Sublime Text 2, there is another IDE that does this?

1 answer

3


Yes, it is possible with the package Sublimerepl, that allows you to run interpreters of several languages within the editor itself.

Open a Python interpreter (Tools > SublimeREPL > Python > Python) and a Python source file. I usually use two columns, leaving the code in one and the interpreter in the other. Place the cursor over the line you want to run and choose Tools > SublimeREPL > Eval in REPL > Lines (or press ctrl and , simultaneously, then release and then press the lowercase L key). Ready, the line will be executed in the interpreter.

This procedure is not so convenient because the cursor does not automatically go to the next line and because there are different commands and shortcut keys to send the current line and to send the selected text. To R, the package Enhanced-R solves these problems. I don’t know if there’s anything like it for Python.

  • Thanks, it worked! Now, another problem, Sublimerepl is using another Python (maybe the Sublime Text 2) and not the Anaconda I have installed. How to change the path of him (as I had to do in the build sublime)?

  • 1

    Try http://stackoverflow.com/questions/20861176/how-do-i-setup-sublimerepl-with-anacondas-interpreter

  • Beauty, thanks! I’ll bring this question to SOPT too, I think it’s important to document here if you want to answer there! Abs

  • 1

    I think you’d better answer it yourself, because I haven’t been using Python in my day-to-day life and haven’t even tested the answer.

  • All right, I’m trying this solution you suggested, if it works I put it there!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.