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 ).
How can I do this?
The Jupyter kernel (ie Python backend) has no direct information about the frontend that is connected to it. 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. I have a Chrome and Safari browsers open currently, and I get these results:
>>> 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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.