2

I am starting to learn python with sublime and ipython. They are cool tools and but I want a way to connect them. I normally have a sublime and a IPython console open. Is there any command that I can run in sublime just send:

runfile('~\someExample.py', wdir='~\myDir')

to the running IPython console?

Thanks!

Yitong Ma
  • 51
  • 2
  • http://stackoverflow.com/questions/8551735/how-do-i-run-python-code-from-sublime-text-2 to run from Sublime, or you can do `exec(open('/path/to/your_file.py').read())` from the iPython command line. – Will Nov 16 '16 at 20:57
  • That link is about running the code in a new python session, not an existing one. – hpaulj Nov 16 '16 at 21:39
  • Did you solve your problem. Want to do the same thing – fossekall Mar 28 '17 at 21:46
  • @fossekall No... Unfortunately. I haven't figured out a way to even starting a new ipython console and run my codes. I will just stick to spyder. – Yitong Ma Mar 30 '17 at 00:21

2 Answers2

1

I edit in geany and use, in ipthon:

run myfile

to load and run myfile.py. ls and cd and pwd are available to check and change the directory.

I save the file from the editor, but I control the run from the ipython console.

If I just need to run the script, I could do a python myfile.py in the editor's terminal window, or maybe via the editor's execute shortcut. But the value in running the code in an existing ipython console is that I can interact with the newly loaded code and variables. I can examine variables, rerun functions with new values, etc.

hpaulj
  • 221,503
  • 14
  • 230
  • 353
0

There is a plugin to do this called SendCode; you can install it directly through the package manager.

As another answer mentioned, you can run some set of shell commands from within ipython, including execution of a file with run python_file.py, as well as other shell commands including cd, mkdir, rm, mv, etc.

anon01
  • 10,618
  • 8
  • 35
  • 58