Python3更新:(引自already-answered answer,自上次编辑/评论以来建议使用不推荐的方法)

In Python 3, reload was moved to the 07001 module. In 3.4, imp was deprecated in favor of 07002, and 07003 was added to the latter. When targeting 3 or later, either reference the appropriate module when calling reload or import it.

带走:

> Python3> = 3.4:importlib.reload(packagename)

> Python3< 3.4:imp.reload(packagename)

> Python2:继续下面

使用reload内置函数:

When reload(module) is executed:

Python modules’ code is recompiled and the module-level code reexecuted, defining a new set of objects which are bound to names in the module’s dictionary. The init function of extension modules is not called a second time.

As with all other objects in Python the old objects are only reclaimed after their reference counts drop to zero.

The names in the module namespace are updated to point to any new or changed objects.

Other references to the old objects (such as names external to the module) are not rebound to refer to the new objects and must be updated in each namespace where they occur if that is desired.

例:

# Make a simple function that prints "version 1"

shell1$echo 'def x(): print "version 1"' > mymodule.py

# Run the module

shell2$python

>>> import mymodule

>>> mymodule.x()

version 1

# Change mymodule to print "version 2" (without exiting the python REPL)

shell2$echo 'def x(): print "version 2"' > mymodule.py

# Back in that same python session

>>> reload(mymodule)

>>> mymodule.x()

version 2

python怎么加载包_如何在Python Interpreter中重新导入更新的包?相关推荐

  1. 如何在Python Interpreter中重新导入更新的包? [重复]

    本文翻译自:How to re import an updated package while in Python Interpreter? [duplicate] This question alr ...

  2. python异步加载图片_如何在PyQt5中正确异步加载图像?

    我在尝试如何在pyqtqlistview中正确地完成异步映像加载.在 我的主小部件由一个Qlistview和一个QLineEdit文本框组成. 我有一个参与者数据库,我使用QAbstractListM ...

  3. python字体加粗代码_如何在python docx中加粗行单元格的文本?

    在python docx中,可以通过使用 Rich Text 造型.您应该为模板中需要样式化的特定字符/字符串在字符/字符串的位置提供一个上下文变量.此变量映射到 RichText 具有样式定义(在代 ...

  4. outlook 加载配置项_如何在Outlook中启用加载项和连接器

    outlook 加载配置项 There are a lot of third-party add-ins and connectors available for Outlook. What's th ...

  5. python构造icmp数据包_如何在python中构造ICMP数据包

    为了学习,我目前正在尝试创建一个简单的python porgram来向某个设备发送ICMP ping数据包.为了开始,我查看了python模块Pyping:https://github.com/Akh ...

  6. python中如何导入数据包_如何在python中发送数据包?

    我尝试使用这段代码在 python中使用scapy发送数据包 data= "University of texas at San Antonio" a=IP(dst="1 ...

  7. python定时刷新tkinter界面_如何在python中“刷新”Tkinter窗口?

    我试图通过一个按钮在Python中重新加载一个Tkinter窗口,但是我很难理解它.你看,它使用import random并从列表中随机生成单词,当你点击按钮时,我想把标签设置成不同的单词,就像掷骰子 ...

  8. python实例化对象做实参_如何在Python中记住类实例化?

    好的,这是真实的场景:我正在编写一个应用程序,我有一个类,它表示某种类型的文件(在我的例子中,这是照片,但细节与问题无关).照片类的每个实例对于照片的文件名都应该是唯一的. 问题是,当用户告诉我的应用 ...

  9. python玩加件大师_如何聘请Python开发人员并确定真正的大师

    python玩加件大师 "The joy of coding is in seeing a short, concise, readable, and small amount of cle ...

最新文章

  1. 解决LaTex中插入Visio画图有多余边框的问题
  2. Docker Caffe部署
  3. menu什么意思中文意思_proclaim什么意思
  4. timertask run函数未执行_函数的防抖和节流是个啥???
  5. Oracle其它数据库对象:视图、序列、同义词
  6. JAVA 通过 Socket 实现 TCP 编程
  7. 文献记录(part42)--An end-to-end framework for unconstrained monocular 3D hand pose estimation
  8. [css] 头部设置meta也可以做到自适应为啥还要用rem?
  9. 计算机操作系统指导书,《计算机操作系统》实验指导书-2015
  10. cf两边黑屏怎么解决win10_关闭自动睡眠仍然睡眠?Win10过几分钟就会自动睡眠黑屏解决方法...
  11. System x借至强5500完成进化
  12. 恭祝月圆·家圆·团圆
  13. 【Transformer】10个重要问题概览Transformer全部内容
  14. 爱好-超级IP:超级IP
  15. 使用docker搭建couchbase集群
  16. Excel里怎么冻结某一行某一列
  17. OVNOVS代码下载、编译安装以及运行步骤
  18. 微观经济学读书笔记(一)
  19. 这一周我学习了什么(一)
  20. R语言编写用户自定义函数:R语言编写用户自定义函数计算变异系数(coefficient of variation)、输入为向量

热门文章

  1. 形态学滤波:(1)腐蚀与膨胀 (2)开运算,闭运算,形态学梯度,顶帽,黑帽...
  2. silverlight中DataGrid错误:data未定义
  3. Sigmatel37xx GPIO的使用
  4. 大罗讲SQL:如何优雅的进行SQL编写?
  5. 实战演练:PostgreSQL在线扩容
  6. 每日一题 丨2020.06.02
  7. 外连接有 OR 关联条件只能走 NL优化
  8. 从 Oracle 到 PostgreSQL :从 Uptime 到数据库实例运行时间
  9. TypeScript 2.0开启空值的严格检查
  10. 【华为云技术分享】云图说 | 一张图看懂华为云弹性公网IP