简体   繁体   English

如何找到 IPython 单元格的宽度?

[英]How do I find the width of an IPython cell?

pandas dataframes are displayed nicely within the ipython cell. pandas 数据框在 ipython 单元格中显示得很好。 How does it do it?它是如何做到的?

The regular ways of getting the console width for Python do not seem to work for ipython cells.获取 Python 控制台宽度的常规方法似乎不适用于 ipython 单元格。

If you just want to see what is the size you can use this script:如果您只想查看大小,可以使用此脚本:

from IPython.display import display, HTML
js = """<script>
alert($( ".cell").width())
</script>"""
display(HTML(js))

If you want to use in code you can assign it to a variable and use it in next cell:如果你想在代码中使用,你可以将它分配给一个变量并在下一个单元格中使用它:

from IPython.display import display, HTML
js = """<script>
IPython.notebook.kernel.execute("cell_width="+($( ".cell").width()))
</script>"""
display(HTML(js))

In the next cell:在下一个单元格中:

print(cell_width)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM