python笔记2019-08-20

安装IPython

安装完Python后即可以用pip命令安装Ipython

安装成功后既可以用Ipython

IPython Documentation — IPython 3.2.1 documentation
http://ipython.org/ipython-doc/stable/index.html

命令名 说明
? ipython特性的介绍和概述
%quickref 一份手册,包含了所有的命令
help python的帮助系统
object? 关于object的详细信息,如果键入object??会更详细

模块重新加载

方法1:用reload

>>> import importlib
>>> importlib.reload(my_module)
进入my_module 模块
'x' is larger than 0
出 my_module 模块
<module 'my_module' from 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python36-32\\my_module.py'>

方法2:在Ipython自动加载所有依赖模块

In [31]: import my_module
进入my_module 模块
出 my_module 模块

In [36]: %load_ext?
Docstring: Load an IPython extension by its module name.
File:      c:\users\administrator\appdata\local\programs\python\python36-32\lib
site-packages\ipython\core\magics\extension.py

In [37]: %load_ext autoreload

In [38]: %autoreload?
Docstring:
%autoreload => Reload modules automatically

%autoreload
Reload all modules (except those excluded by %aimport) automatically
now.

%autoreload 0
Disable automatic reloading.

%autoreload 1
Reload all modules imported with %aimport every time before executing
the Python code typed.

%autoreload 2
Reload all modules (except those excluded by %aimport) every time
before executing the Python code typed.

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:

In [39]: %autoreload 2

In [40]: import my_module

In [41]: my_module.test1()
函数test1输出成功

In [42]:#change mymodule.py

In [43]: my_module.test1() #my_module.test1在执行时,先加载my_module,在执行test1
进入my_module 模块
出 my_module 模块
--函数test1输出成功

猜你喜欢

转载自blog.csdn.net/dreamfly130/article/details/81873011