Python、ipython、shell

登陆linux环境,已安装Anaconda(一个开源的Python发行版本,其包含了conda、Python等180多个科学包及其依赖项),最常用的就是输入“python”,进入python环境。偶然看到师弟用ipython进入环境,好奇查询了以下区别。

python shell与ipython的区别:

(1) python shell不能在退出保存历史;

ipython历史记录自动保存:

        保存在history.sqlite文件下:

可用“_”、“__”、“___”调用最近三次记录;

(2) python shell不支持tab自动补全;

ipython支持tab补全;

(3) python shell不能快速获取类、函数信息;

ipython通过“?”显示对象签名、文档字符串、代码位置,通过“??”显示源代码;

(4) python shell不能直接执行shell命令,需要借助sys;

ipython通过“!”调用系统命令,如“!uptime”;

(5) 其他

ipython有很多magic函数,可通过使用%lsmagic枚举;

%run:运行python文件

%edit:使用编辑器打开当前函数编辑

%save:把某些历史记录保存到文件

%debug:激活debug程序

%timeit:获得程序执行时间

%paste:获取剪切板文件并执行,最好用%cpaste,可通过Ctrl+C中断

ipython有很多快捷键


ipython的扩展宏系统

storemagic持久化宏、变量、别名;

autoreload自动重载;


参考资料

(简单版)https://www.zhihu.com/question/51467397?from=profile_question_card

(全面版)https://www.cnblogs.com/zzhzhao/p/5295476.html
---------------------
作者:CS青雀
来源:CSDN
原文:https://blog.csdn.net/ztf312/article/details/78677093
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自blog.csdn.net/Scrat_Kong/article/details/83177840