python - 如何在终端中以 'page' 打印带有 html 内容的 python 变量?

标签 python html terminal

我有一个带有 html 内容的 python 变量

>>>>a='<html><h1><a href="http://www.google.com">Link to Google<></h1></html>'

如何将其打印为 html?

我想在我的终端中打印这个变量,我想要这样的结果:

a.html

OBS.: 如果 python 可以在没有 shell 脚本或其他程序的情况下做到这一点,我会更喜欢这个。

最佳答案

我成功地做了一个 python 程序 a.py 如下:

a='<html><h1>My example text</h1></html>'
file=open("a.html","w")
file.write(a+'\n')
file.close

然后执行另一个 shell 脚本 a.sh,例如:

#!/bin/sh
/usr/bin/env python a.py
w3m a.html

但是我觉得不是什么好办法,不是只有python的吗?

关于python - 如何在终端中以 'page' 打印带有 html 内容的 python 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8074448/

相关文章:

python - 将 Blender2.79 代码转换为 Blender2.8 : game sensors

python - 在 Python 中对列表中的每个项目进行线程处理

python - Jython 不会将 PYTHONPATH 加载到 sys.path 中

python - 在不删除表的情况下更改模型中的 Django 数据类型

macos - Composer 不适用于oh-my-zsh

linux - 如何获取终端属性

php - 为用户输入创建 PHP 页面和弹出窗口时出现 Ajax 问题

html - 如何在表格 td 字段中设置固定宽度?

javascript - 在 jsp 中使 div 不可刷新(不使用 AJAX)

shell - 设备/dev/ttyusb0 锁定失败 : operation not permitted