如何通过“manage”来重新加载Django模型模块。py壳”?

时间:2021-01-17 20:41:31

I know how to reload a regular Python module within a regular Python interpreter session. This question documents how to do that pretty well:

我知道如何在常规的Python解释器会话中重新加载常规的Python模块。这个问题证明了如何做到这一点:

How do I unload (reload) a Python module?

如何卸载(重载)Python模块?

For some reason, I am having trouble doing that within Django's "manage.py shell" interpreter session. To recreate my issue, start the basic Django tutorial found here:

出于某种原因,我在Django的“管理”中遇到了麻烦。py壳”翻译会话。要重新创建我的问题,可以在这里找到基本的Django教程:

Writing your first Django app, part 1

编写第一个Django应用程序,第1部分。

After creating the "polls" application and "Poll" class, start up the interpreter via "manage.py shell" and import the "polls" app into it.

在创建“Poll”应用程序和“Poll”类之后,通过“manage”启动解释器。“py shell”并将“投票”应用程序导入它。

import polls.models as pm

Create a new "Poll" object:

创建一个新的“Poll”对象:

p = pm.Poll()

All is well and good so far. Now go back to your source and add any arbitrary method or attribute. For example, I've added:

到目前为止一切顺利。现在回到您的源代码并添加任意的方法或属性。例如,我说:

def x(self):
    return 2+2

Now go back to the interpreter and "reload" the module:

现在回到解释器并“重新加载”模块:

reload(pm)

Now try to use your new method or attribute:

现在尝试使用你的新方法或属性:

p1 = pm.Poll()
p1.x()

You'll get this message:

你会得到这个消息:

'Poll' object has no attribute 'x'

What gives? I've also tried rerunning the import command, importing the module using different syntax, deleting all references to any "Poll" objects or to the "Poll" class. I've also tried this with both the IPython interpreter and with the plain Python (v2.6) interpreter. Nothing seems to work.

到底发生了什么事?我还尝试过重新运行import命令,使用不同的语法导入模块,删除对任何“Poll”对象的所有引用,或者对“Poll”类进行删除。我还使用了IPython解释器和普通Python (v2.6)解释器进行了测试。似乎没有什么工作。

Using the same techniques with an arbitrary Python module in a regular interpreter session works perfectly. I just can't seem to get it to work in Django's "shell" session.

在常规解释器会话中,使用与任意Python模块相同的技术可以很好地工作。我似乎无法让它在Django的“shell”会话中工作。

By the way, if it makes any difference, I'm doing this on a Ubuntu 9.04 machine.

顺便说一下,如果这有什么区别的话,我是在Ubuntu 9.04机器上做的。

9 个解决方案

#1


38  

Well, I think I have to answer to this. The problem is that Django caches its models in a singleton (singleton like structure) called AppCache. Basically, to reload Django models you need to first reload and re-import all the model modules stored in the AppCache. Then you need to wipe out the AppCache. Here's the code for it:

嗯,我想我必须回答这个问题。问题是Django在一个名为AppCache的单例(单例结构)中缓存它的模型。基本上,为了重新加载Django模型,您需要首先重新加载并重新导入存储在AppCache中的所有模型模块。然后需要清除AppCache。下面是它的代码:

import os
from django.db.models.loading import AppCache
cache = AppCache()

curdir = os.getcwd()

for app in cache.get_apps():
    f = app.__file__
    if f.startswith(curdir) and f.endswith('.pyc'):
        os.remove(f)
    __import__(app.__name__)
    reload(app)

from django.utils.datastructures import SortedDict
cache.app_store = SortedDict()
cache.app_models = SortedDict()
cache.app_errors = {}
cache.handled = {}
cache.loaded = False

I've put all of this in a separate file called reloadmodels.py in the root directory of my Django site. Using IPython I can reload everything by running:

我把所有这些都放在一个叫做reloadmodels的单独文件中。py在我的Django站点的根目录中。使用IPython,我可以通过运行来重新加载所有东西:

%run ~/mysite/reloadmodels.py

#2


6  

You can also use django-extensions project with the following command:

您还可以使用以下命令使用django-extensions项目:

manage.py shell_plus --notebook

This will open a IPython notebook on your web browser instead of the IPython shell interpreter. Write your code there, and run it.

这将在您的web浏览器上打开一个IPython笔记本,而不是IPython shell解释器。在那里编写代码并运行它。

When you change your modules, just click on the web page menu item 'Kernel->Restart'

当您更改模块时,只需单击web页面菜单项“Kernel->Restart”即可。

Re-running the code now uses your modified modules.

重新运行代码现在使用您的修改模块。

#3


5  

Assuming your project is set up this way

假设您的项目是这样设置的。

  • project name : bookstore
  • 项目名称:书店
  • app name : shelf
  • 应用名称:货架
  • model name : Books
  • 模型名称:图书

first load

第一次加载

from bookstore.shelf.models import Books

subsequent reloads

随后的重新加载

import bookstore;reload(bookstore.shelf.models);from bookstore.shelf.models import Books

#4


5  

As far as I'm concerned, none of the above solutions worked on their own, also this thread didn't help much on its own, but after combining the approaches I managed to reload my models in shell_plus:

在我看来,以上的解决方案都不是自己解决的,而且这个线程本身也没有多大帮助,但是在结合了这些方法之后,我成功地在shell_plus中重新加载了我的模型:

  1. Make changes to the model (MyModel)
  2. 对模型进行更改(MyModel)
  3. remove models.pyc
  4. 删除models.pyc
  5. Clean Django model cache (like here):

    Clean Django模型缓存(如下所示):

     from django.db.models.loading import AppCache
     cache = AppCache()
     from django.utils.datastructures import SortedDict
     cache.app_store = SortedDict()
     cache.app_models = SortedDict()
     cache.app_errors = {}
     cache.handled = {}
     cache.loaded = False
    
  6. Reload model like here

    重新加载模型像这里

    reload(project.app.models)
    from project.app.models import MyModel
    

#5


3  

ipython console does a deep reload with each reload() expression; and of course adds a lot of other useful stuff.

ipython控制台在每个重载()表达式中执行深度重载;当然还有很多其他有用的东西。

#6


3  

My solution on 2016 (in future it may be changed)

2016年我的解决方案(未来可能会改变)

1.Install django_extension

1。安装django_extension

2.Add next settings:

2。添加下一个设置:

SHELL_PLUS = 'ipython'

IPYTHON_ARGUMENTS = [
    '--ext', 'autoreload',
]

3.Run shell

3所示。运行shell

./manage.py shell_plus

See results:

model example

模型示例

class Notification(models.Model):

    ........

    @classmethod
    def get_something(self):

        return 'I am programmer'

In shell

在壳牌

In [1]: Notification.get_something()
Out[1]: 'I am programmer'

Made changes on model

对模型做了一些改变

@classmethod
    def get_something(self):

        return 'I am Python programmer'

In shell

在壳牌

# shell does not display changes
In [2]: Notification.get_something()
Out[2]: 'I am programmer'

In shell. This is a magic

在shell。这是一个魔术

# configure extension of ipython
In [3]: %autoreload 2

In shell

在壳牌

# try again - all worked
In [4]: Notification.get_something()
Out[4]: 'I am Python programmer'

Made changes again

又做了一些改变

    @classmethod
    def get_something(self):

        return 'I am full-stack Python programmer'

In shell

在壳牌

# all worked again
In [5]: Notification.get_something()
Out[5]: 'I am full-stack Python programmer'

Drawback: 1. Need manually run code

缺点:1。需要手动运行代码

%autoreload 2

% autoreload 2

since django_extension 1.7 has not support for run arbitrary code. May be in future release it has this feature.

因为django_extension 1.7不支持运行任意代码。可能在未来的版本中有这个功能。

Notes:

注:

  1. Django 1.10
  2. Django 1.10
  3. Python 3.4
  4. Python 3.4
  5. django_extension 1.7.4
  6. django_extension 1.7.4
  7. Based (primary) on https://django-extensions.readthedocs.io/en/latest/shell_plus.html and http://ipython.readthedocs.io/en/stable/config/extensions/autoreload.html
  8. (初级)基于https://django-extensions.readthedocs.io/en/latest/shell_plus。html和http://ipython.readthedocs.io/en/stable/config/extensions/autoreload.html
  9. Caution. It is may be produce an error, if you try change a code where used super().
  10. 谨慎。如果您尝试更改使用super()的代码,可能会产生错误。

#7


1  

Enable IPython autoreload extension before importing any code:

在导入任何代码之前启用IPython autoreload扩展:

%load_ext autoreload
%autoreload 2

I use it with the regular django shell and it works perfectly, although it does have some limitations:

我使用的是常规的django shell,它运行得很好,尽管它有一些限制:

*Caveats:

*说明:

Reloading Python modules in a reliable way is in general difficult, and unexpected things may occur. %autoreload tries to work around common pitfalls by replacing function code objects and parts of classes previously in the module with new versions. This makes the following things to work:

以可靠的方式重新加载Python模块通常是困难的,可能会发生意想不到的事情。%autoreload试图通过替换函数代码对象和以前在模块中使用新版本的类的部分来解决常见的缺陷。这就使得下面的事情成为可能:

  • Functions and classes imported via ‘from xxx import foo’ are upgraded to new versions when ‘xxx’ is reloaded.
  • 通过“xxx导入foo”导入的函数和类在“xxx”重新加载时升级为新版本。
  • Methods and properties of classes are upgraded on reload, so that calling ‘c.foo()’ on an object ‘c’ created before the reload causes the new code for ‘foo’ to be executed.
  • 类的方法和属性在重载上进行了升级,因此在重新加载之前创建的对象“c”上的“c.foo()”将导致执行“foo”的新代码。

Some of the known remaining caveats are:

一些已知的警告是:

  • Replacing code objects does not always succeed: changing a @property in a class to an ordinary method or a method to a member variable can cause problems (but in old objects only).
  • 替换代码对象并不总是成功:将类中的@property更改为普通方法或成员变量的方法会导致问题(但仅在旧对象中)。
  • Functions that are removed (eg. via monkey-patching) from a module before it is reloaded are not upgraded.
  • 删除的函数(如。通过monkey-patching)在它被重新加载之前的模块没有升级。
  • C extension modules cannot be reloaded, and so cannot be autoreloaded.*
  • 不能重新加载C扩展模块,因此不能自动加载。*。

source: https://ipython.org/ipython-doc/3/config/extensions/autoreload.html#caveats

来源:https://ipython.org/ipython-doc/3/config/extensions/autoreload.html警告

Another great option is to write your code in a separate script and send it to django shell, like this:

另一个不错的选择是,在一个单独的脚本中编写代码并将其发送到django shell,如下所示:

manage.py shell < my_script.py

#8


1  

From the answers of Seti Volkylany and pv

从Seti Volkylany和pv的答案。

  1. Install IPython: pip install ipython
  2. 安装IPython: pip安装IPython。
  3. Run python manage.py shell : the symbol at the beginning of a line should now be In [1]: (in cmd it was >>>)
  4. python运行管理。py shell:在一行开始时的符号现在应该在[1]:(cmd中是>>>)
  5. Run ipython profile create
  6. 运行ipython概要文件创建
  7. Go in ~/.ipython/profile_default/ipython_config.py and open it in a text editor and add these two lines at the end:

    在~ / .ipython / profile_default / ipython_config。py并在文本编辑器中打开,并在末尾添加这两行:

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

    c.InteractiveShellApp。扩展= ' autoreload c.InteractiveShellApp。exec_lines =(“% autoreload 2”)

You can now run python manage.py shell, edit your models without having to write %autoreload 2

现在可以运行python管理。py shell,编辑您的模型而不需要写%autoreload 2。

#9


0  

I wasn't able to get any of the above solutions to work, but I did come up with a workaround for reloading any other non-models module in my django project (e.g. a functions.py or views.py module).

我无法获得上面的任何解决方案,但我确实找到了一个变通方法,以便在django项目中重新加载任何其他非模型模块(例如,一个函数)。py或视图。py模块)。

  1. Create a file called reimport_module.py. I stored it in the local/ folder of my django project on my dev machine.

    创建一个名为reimport_module.py的文件。我将它存储在我的dev机器上django项目的本地/文件夹中。

    # Desc: Imports the module with the name passed in, or imports it for first
    #       time if it hasn't already been imported.
    #
    #       Purpose of this script is to speed up development of functions that
    #       are written in an external editor then tested in IPython.
    #
    #       Without this script you have to exit & reenter IPython then redo
    #       import statements, definitions of local variables, etc.
    #
    #       Note: doesn't work for Django models files, because Django caches
    #       them in a structure called AppCache.
    #
    # Args: module to reload (string)
    
    import sys
    
    module_to_reload = sys.argv[1]
    
    # Attempt to pop module
    try:
        sys.modules.pop(module_to_reload)
        print 'reimporting...'
    except KeyError:
        print 'importing for first time...'
    
    # (re)import module
    import_str = 'from {0} import *'.format(module_to_reload)
    exec(import_str) 
    
  2. Launch shell plus (which uses an embedded IPython shell):

    启动shell plus(使用嵌入式IPython shell):

    python manage.py shell_plus

    python管理。py shell_plus

  3. Use the following to import the module you are developing:

    使用以下方法导入正在开发的模块:

    %run local/reimport_module.py 'your.module'

    %本地/ reimport_module运行。py your.module”

  4. Use IPython to test functions in your module.

    使用IPython测试模块中的函数。

  5. Make changes to the module in an external editor.
  6. 在外部编辑器中对模块进行更改。
  7. Use the following to reimport the module without having to exit & reenter IPython:

    使用以下命令重新导入模块,而不必退出和重新进入IPython:

    %run local/reimport_module.py 'your.module'

    %本地/ reimport_module运行。py your.module”

    Note: this command was already used in step 3, so you can type %run then the up arrow to autocomplete it.

    注意:这个命令已经在步骤3中使用,所以您可以输入%run然后向上箭头来自动完成它。

#1


38  

Well, I think I have to answer to this. The problem is that Django caches its models in a singleton (singleton like structure) called AppCache. Basically, to reload Django models you need to first reload and re-import all the model modules stored in the AppCache. Then you need to wipe out the AppCache. Here's the code for it:

嗯,我想我必须回答这个问题。问题是Django在一个名为AppCache的单例(单例结构)中缓存它的模型。基本上,为了重新加载Django模型,您需要首先重新加载并重新导入存储在AppCache中的所有模型模块。然后需要清除AppCache。下面是它的代码:

import os
from django.db.models.loading import AppCache
cache = AppCache()

curdir = os.getcwd()

for app in cache.get_apps():
    f = app.__file__
    if f.startswith(curdir) and f.endswith('.pyc'):
        os.remove(f)
    __import__(app.__name__)
    reload(app)

from django.utils.datastructures import SortedDict
cache.app_store = SortedDict()
cache.app_models = SortedDict()
cache.app_errors = {}
cache.handled = {}
cache.loaded = False

I've put all of this in a separate file called reloadmodels.py in the root directory of my Django site. Using IPython I can reload everything by running:

我把所有这些都放在一个叫做reloadmodels的单独文件中。py在我的Django站点的根目录中。使用IPython,我可以通过运行来重新加载所有东西:

%run ~/mysite/reloadmodels.py

#2


6  

You can also use django-extensions project with the following command:

您还可以使用以下命令使用django-extensions项目:

manage.py shell_plus --notebook

This will open a IPython notebook on your web browser instead of the IPython shell interpreter. Write your code there, and run it.

这将在您的web浏览器上打开一个IPython笔记本,而不是IPython shell解释器。在那里编写代码并运行它。

When you change your modules, just click on the web page menu item 'Kernel->Restart'

当您更改模块时,只需单击web页面菜单项“Kernel->Restart”即可。

Re-running the code now uses your modified modules.

重新运行代码现在使用您的修改模块。

#3


5  

Assuming your project is set up this way

假设您的项目是这样设置的。

  • project name : bookstore
  • 项目名称:书店
  • app name : shelf
  • 应用名称:货架
  • model name : Books
  • 模型名称:图书

first load

第一次加载

from bookstore.shelf.models import Books

subsequent reloads

随后的重新加载

import bookstore;reload(bookstore.shelf.models);from bookstore.shelf.models import Books

#4


5  

As far as I'm concerned, none of the above solutions worked on their own, also this thread didn't help much on its own, but after combining the approaches I managed to reload my models in shell_plus:

在我看来,以上的解决方案都不是自己解决的,而且这个线程本身也没有多大帮助,但是在结合了这些方法之后,我成功地在shell_plus中重新加载了我的模型:

  1. Make changes to the model (MyModel)
  2. 对模型进行更改(MyModel)
  3. remove models.pyc
  4. 删除models.pyc
  5. Clean Django model cache (like here):

    Clean Django模型缓存(如下所示):

     from django.db.models.loading import AppCache
     cache = AppCache()
     from django.utils.datastructures import SortedDict
     cache.app_store = SortedDict()
     cache.app_models = SortedDict()
     cache.app_errors = {}
     cache.handled = {}
     cache.loaded = False
    
  6. Reload model like here

    重新加载模型像这里

    reload(project.app.models)
    from project.app.models import MyModel
    

#5


3  

ipython console does a deep reload with each reload() expression; and of course adds a lot of other useful stuff.

ipython控制台在每个重载()表达式中执行深度重载;当然还有很多其他有用的东西。

#6


3  

My solution on 2016 (in future it may be changed)

2016年我的解决方案(未来可能会改变)

1.Install django_extension

1。安装django_extension

2.Add next settings:

2。添加下一个设置:

SHELL_PLUS = 'ipython'

IPYTHON_ARGUMENTS = [
    '--ext', 'autoreload',
]

3.Run shell

3所示。运行shell

./manage.py shell_plus

See results:

model example

模型示例

class Notification(models.Model):

    ........

    @classmethod
    def get_something(self):

        return 'I am programmer'

In shell

在壳牌

In [1]: Notification.get_something()
Out[1]: 'I am programmer'

Made changes on model

对模型做了一些改变

@classmethod
    def get_something(self):

        return 'I am Python programmer'

In shell

在壳牌

# shell does not display changes
In [2]: Notification.get_something()
Out[2]: 'I am programmer'

In shell. This is a magic

在shell。这是一个魔术

# configure extension of ipython
In [3]: %autoreload 2

In shell

在壳牌

# try again - all worked
In [4]: Notification.get_something()
Out[4]: 'I am Python programmer'

Made changes again

又做了一些改变

    @classmethod
    def get_something(self):

        return 'I am full-stack Python programmer'

In shell

在壳牌

# all worked again
In [5]: Notification.get_something()
Out[5]: 'I am full-stack Python programmer'

Drawback: 1. Need manually run code

缺点:1。需要手动运行代码

%autoreload 2

% autoreload 2

since django_extension 1.7 has not support for run arbitrary code. May be in future release it has this feature.

因为django_extension 1.7不支持运行任意代码。可能在未来的版本中有这个功能。

Notes:

注:

  1. Django 1.10
  2. Django 1.10
  3. Python 3.4
  4. Python 3.4
  5. django_extension 1.7.4
  6. django_extension 1.7.4
  7. Based (primary) on https://django-extensions.readthedocs.io/en/latest/shell_plus.html and http://ipython.readthedocs.io/en/stable/config/extensions/autoreload.html
  8. (初级)基于https://django-extensions.readthedocs.io/en/latest/shell_plus。html和http://ipython.readthedocs.io/en/stable/config/extensions/autoreload.html
  9. Caution. It is may be produce an error, if you try change a code where used super().
  10. 谨慎。如果您尝试更改使用super()的代码,可能会产生错误。

#7


1  

Enable IPython autoreload extension before importing any code:

在导入任何代码之前启用IPython autoreload扩展:

%load_ext autoreload
%autoreload 2

I use it with the regular django shell and it works perfectly, although it does have some limitations:

我使用的是常规的django shell,它运行得很好,尽管它有一些限制:

*Caveats:

*说明:

Reloading Python modules in a reliable way is in general difficult, and unexpected things may occur. %autoreload tries to work around common pitfalls by replacing function code objects and parts of classes previously in the module with new versions. This makes the following things to work:

以可靠的方式重新加载Python模块通常是困难的,可能会发生意想不到的事情。%autoreload试图通过替换函数代码对象和以前在模块中使用新版本的类的部分来解决常见的缺陷。这就使得下面的事情成为可能:

  • Functions and classes imported via ‘from xxx import foo’ are upgraded to new versions when ‘xxx’ is reloaded.
  • 通过“xxx导入foo”导入的函数和类在“xxx”重新加载时升级为新版本。
  • Methods and properties of classes are upgraded on reload, so that calling ‘c.foo()’ on an object ‘c’ created before the reload causes the new code for ‘foo’ to be executed.
  • 类的方法和属性在重载上进行了升级,因此在重新加载之前创建的对象“c”上的“c.foo()”将导致执行“foo”的新代码。

Some of the known remaining caveats are:

一些已知的警告是:

  • Replacing code objects does not always succeed: changing a @property in a class to an ordinary method or a method to a member variable can cause problems (but in old objects only).
  • 替换代码对象并不总是成功:将类中的@property更改为普通方法或成员变量的方法会导致问题(但仅在旧对象中)。
  • Functions that are removed (eg. via monkey-patching) from a module before it is reloaded are not upgraded.
  • 删除的函数(如。通过monkey-patching)在它被重新加载之前的模块没有升级。
  • C extension modules cannot be reloaded, and so cannot be autoreloaded.*
  • 不能重新加载C扩展模块,因此不能自动加载。*。

source: https://ipython.org/ipython-doc/3/config/extensions/autoreload.html#caveats

来源:https://ipython.org/ipython-doc/3/config/extensions/autoreload.html警告

Another great option is to write your code in a separate script and send it to django shell, like this:

另一个不错的选择是,在一个单独的脚本中编写代码并将其发送到django shell,如下所示:

manage.py shell < my_script.py

#8


1  

From the answers of Seti Volkylany and pv

从Seti Volkylany和pv的答案。

  1. Install IPython: pip install ipython
  2. 安装IPython: pip安装IPython。
  3. Run python manage.py shell : the symbol at the beginning of a line should now be In [1]: (in cmd it was >>>)
  4. python运行管理。py shell:在一行开始时的符号现在应该在[1]:(cmd中是>>>)
  5. Run ipython profile create
  6. 运行ipython概要文件创建
  7. Go in ~/.ipython/profile_default/ipython_config.py and open it in a text editor and add these two lines at the end:

    在~ / .ipython / profile_default / ipython_config。py并在文本编辑器中打开,并在末尾添加这两行:

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

    c.InteractiveShellApp。扩展= ' autoreload c.InteractiveShellApp。exec_lines =(“% autoreload 2”)

You can now run python manage.py shell, edit your models without having to write %autoreload 2

现在可以运行python管理。py shell,编辑您的模型而不需要写%autoreload 2。

#9


0  

I wasn't able to get any of the above solutions to work, but I did come up with a workaround for reloading any other non-models module in my django project (e.g. a functions.py or views.py module).

我无法获得上面的任何解决方案,但我确实找到了一个变通方法,以便在django项目中重新加载任何其他非模型模块(例如,一个函数)。py或视图。py模块)。

  1. Create a file called reimport_module.py. I stored it in the local/ folder of my django project on my dev machine.

    创建一个名为reimport_module.py的文件。我将它存储在我的dev机器上django项目的本地/文件夹中。

    # Desc: Imports the module with the name passed in, or imports it for first
    #       time if it hasn't already been imported.
    #
    #       Purpose of this script is to speed up development of functions that
    #       are written in an external editor then tested in IPython.
    #
    #       Without this script you have to exit & reenter IPython then redo
    #       import statements, definitions of local variables, etc.
    #
    #       Note: doesn't work for Django models files, because Django caches
    #       them in a structure called AppCache.
    #
    # Args: module to reload (string)
    
    import sys
    
    module_to_reload = sys.argv[1]
    
    # Attempt to pop module
    try:
        sys.modules.pop(module_to_reload)
        print 'reimporting...'
    except KeyError:
        print 'importing for first time...'
    
    # (re)import module
    import_str = 'from {0} import *'.format(module_to_reload)
    exec(import_str) 
    
  2. Launch shell plus (which uses an embedded IPython shell):

    启动shell plus(使用嵌入式IPython shell):

    python manage.py shell_plus

    python管理。py shell_plus

  3. Use the following to import the module you are developing:

    使用以下方法导入正在开发的模块:

    %run local/reimport_module.py 'your.module'

    %本地/ reimport_module运行。py your.module”

  4. Use IPython to test functions in your module.

    使用IPython测试模块中的函数。

  5. Make changes to the module in an external editor.
  6. 在外部编辑器中对模块进行更改。
  7. Use the following to reimport the module without having to exit & reenter IPython:

    使用以下命令重新导入模块,而不必退出和重新进入IPython:

    %run local/reimport_module.py 'your.module'

    %本地/ reimport_module运行。py your.module”

    Note: this command was already used in step 3, so you can type %run then the up arrow to autocomplete it.

    注意:这个命令已经在步骤3中使用,所以您可以输入%run然后向上箭头来自动完成它。