gpt4 book ai didi

Python: `.to_html() function` 使用 `urllib.requests` 在浏览器中打开 pandas 数据框

转载 作者:太空宇宙 更新时间:2023-11-03 21:29:26 26 4
gpt4 key购买 nike

我看到使用Django或Flask渲染html有很多不同的版本,但是是否可以渲染通过python生成的html以在浏览器中显示?如果是,可以指定浏览器还是默认系统浏览器?

我现在有了代码,可以给我一个 html 格式的 pandas 数据框(使用 .to_html()),但我需要在浏览器中打开它。

最佳答案

有一个名为 webbrowser 的模块可以做到这一点

#!/usr/bin/python36

import webbrowser, os

with open(filename, "w") as f: f.write(html)

browser_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'

webbrowser.get(browser_path).open('file://' + os.path.realpath(filename))

关于Python: `.to_html() function` 使用 `urllib.requests` 在浏览器中打开 pandas 数据框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53618718/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com