python - __class__ 实现在 IPython 中是否针对 Python 进行了修改?
问题描述
我正在尝试将__class__
Python 和 IPython 中的type()
函数与两者中的函数进行比较,并想知道以下行为差异是否是因为__class__
IPython wrt Python 中的修改。
Python
>>> [].__class__
<class 'list'>
>>> type([])
<class 'list'>
IPython
In [2]: [].__class__
Out[2]: list
In [3]: type([])
Out[3]: list
但是对于 print 它似乎仍然是指 Python 的__class__
Python
>>> print(type([]))
<class 'list'>
IPython
In [4]: print(type([]))
<class 'list'>
解决方案
这就是神奇发生的地方:
In [1] import sys
In [2] sys.displayhook
Out[2]: <IPython.terminal.prompts.RichPromptDisplayHook at 0x7f6c42b08190>
对比
>>> import sys
>>> sys.displayhook
<built-in function displayhook>
显示的对象(list
或<class 'list'>
)是同一个对象。使用sys.displayhook
,IPython 修改它在交互式 REPL 中的显示方式。
推荐阅读
- python - 简单循环的问题
- c# - unity c# json 字符串到 2020 年列表/字典
- java - 有什么方法可以找出为什么会出现以下索引错误?
- vb.net - 将图片框图像导出到本地磁盘
- android - 发送带有 POST 请求 url 编码的 JSONObject 和改造
- javascript - Flutter Web - 是否可以监听击键事件?
- azure - 如何在服务总线队列触发功能中将服务总线消息移动到死信
- assembly - 汇编语言编程声明
- php - Laravel 5 在分类编辑页面,顶部分类选择框选中的列表
- postgresql - Google Cloud SQL - 来自 QGIS 的 PostgreSQL 数据库连接,用于第三方