[英]In Jupyter, how do you tell which browser you are in?
In my Jupyter notebook, I need to know whether I am running in Chrome or Firefox because the code to save a figure in Altair is different depending on the browser ( https://altair-viz.github.io/user_guide/saving_charts.html ).在我的 Jupyter 笔记本中,我需要知道我是在 Chrome 还是 Firefox 中运行,因为在 Altair 中保存图形的代码因浏览器而异( https://altair-viz.github.io/user_guide/saving_charts.html )。
How can I do this?我怎样才能做到这一点?
The Jupyter kernel (ie Python backend) has no direct information about the frontend that is connected to it. Jupyter 内核(即 Python 后端)没有关于连接到它的前端的直接信息。 But you can use system tools to try to infer what browser processes are running.但是您可以使用系统工具来尝试推断正在运行的浏览器进程。 For example, the psutil module allows you to list running processes.例如, psutil模块允许您列出正在运行的进程。 I have a Chrome and Safari browsers open currently, and I get these results:我当前打开了 Chrome 和 Safari 浏览器,得到以下结果:
>>> import psutil
>>> 'Google Chrome' in (p.name() for p in psutil.process_iter())
True
>>> 'Firefox' in (p.name() for p in psutil.process_iter())
False
>>> 'Safari' in (p.name() for p in psutil.process_iter())
True
Some caveats:一些注意事项:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.