我有一个带有 html 内容的 python 变量
>>>>a='<html><h1><a href="http://www.google.com">Link to Google<></h1></html>'
如何将其打印为 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/