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一份手册,包含了所有的命令
helppython的帮助系统
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输出成功

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值