在emacs python shell中重新加载一个改变的python文件 [英] Reloading a changed python file in emacs python shell

查看:135
本文介绍了在emacs python shell中重新加载一个改变的python文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Emacs的Python shell(我正在运行2. * Python)我正在导入一个.py文件,我正在使用和测试代码。如果我更改代码,但我不知道如何再次导入。



从我的阅读到目前为止,似乎

  reload(modulename )

应该工作,但似乎没有。



也许只是关闭python shell并重新启动它就足够了,是否有一个命令,或者你只是手动执行?



编辑:看起来像python-send-defun和python-send-buffer是理想的,但是变化似乎并没有被传播。

解决方案

似乎对我有用:



将一个文件(在你的PYTHONPATH中)称为test.py

  def foo():
print('bar')


$ $ $ $ $ $ $ $ $ $ $ $ $ $ code>>>>导入测试
>>> test.foo()
bar

现在修改test.py:

  def foo():
print('baz')

>>>从/home/unutbu/pybin/test.py'>重新加载(测试)
< module'test'
>>> test.foo()
baz


In the emacs Python shell (I'm running 2.* Python) I am importing a .py file I'm working with and testing the code. If I change the code however I'm not sure how to import it again.

From my reading so far it seems that

reload(modulename)

should work, but it doesn't seem to.

Perhaps just shutting down the python shell and restarting it would be enough, is there a command for that or you just do it manually?

edit: It looks like python-send-defun and python-send-buffer would be ideal, but changes don't seem to be propagating.

解决方案

It seems to work for me:

Make a file (in your PYTHONPATH) called test.py

def foo():
    print('bar')

Then in the emacs python shell (or better yet, the ipython shell), type

>>> import test
>>> test.foo()
bar

Now modify test.py:

def foo():
    print('baz')

>>> reload(test)
<module 'test' from '/home/unutbu/pybin/test.py'>
>>> test.foo()
baz

这篇关于在emacs python shell中重新加载一个改变的python文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆