ipython - 读取 ipython 神奇的“精度”值
问题描述
ipython
您可以使用魔术功能设置打印精度precision
:
In [1]: %precision 2
Out[1]: '%.2f'
In [2]: 5/7
Out[2]: 0.71
您还可以通过 ipython 对象发出命令:
ipython = get_ipython()
ipython.run_line_magic("precision", "2")
但是你如何获得字符串'%.2f'
?
有没有类似的命令ipython.get_magic_value('precision')
?
解决方案
找到了解决方案:
from IPython import get_ipython
ipython = get_ipython()
ipython.run_line_magic("precision", "3")
# you could also type %precision 3
form = ipython.display_formatter.formatters['text/plain']
form.float_format
#yields: '%.3f'
form.float_precision
#yields '3'
推荐阅读
- python - 对数据框行的操作
- sql - SQL - 使用服务组合查找帐户
- sqlite - 限制具有别名的列的结果
- sql - 为什么向 LIKE 添加第二个选项似乎撤消了我的 date = 功能?
- android - Android Room DAO 获得一个带有 crossRef 的字段
- google-apps-script - Google Apps 脚本在大约 30 秒内显示“超过最大执行时间”
- windows - Firefox 支持的拖放目标格式
- php - 如何通过访问其他表来获取所有被阻止的客户端来获取它
- javascript - 如何在赛普拉斯中获取具有动态选择器的元素
- roblox - 如何在 Roblox 中制作这些“提示”外观的东西?