2

When I use python-shell-send-buffer (C-c C-c) I can see changes from my main buffer in python shell.

But if my buffer has imported modules they are not reloaded. How can it be fixed?

For exmple:
main.py:

from functions import foo
print 'a'

functions.py:

def foo():
    print 'bcdef'

So if I change foo() and run python-shell-send-buffer on main.py - it gives me the same foo() it read 1st time

a
bcdef   # never changed

1 Answer 1

0

If you want to do this - use ipython.

Create configuration "dev" (or whatever):

ipython profile create dev
[ProfileCreate] Generating default config file: u'/home/username/.config/ipython/profile_dev/ipython_config.py'

And add these lines to "ipython_config.py":

c.InteractiveShellApp.extensions = ['autoreload']
c.InteractiveShellApp.exec_lines = ['%autoreload 2']

Then set variables in Emacs config for python-mode:

(setq
   python-shell-interpreter "ipython"
   python-shell-interpreter-args "--profile=dev"
)

IPython started with this config will reload modules when you resend code to it.

Sign up to request clarification or add additional context in comments.

1 Comment

When I press C-c C-p the console opens with the following error: IPython profile: dev ^[[6n^[[JIn [1]: ^[[8D^[[8C. Maybe it is related to %autoreload 2, what is the meaning of the % symbol and of 2?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.