python - 为什么python模块requests_html仅在从输出中的字符串导入后取消粗体和下划线效果?
问题描述
所以我有这个代码。
只是一些红色、粗体、下划线和 endc 的 ansi 转义码。该代码正在屏幕上打印修改后的字符串。
bold = "\033[1m"
underlined = "\033[4m"
red = "\033[91m"
endc = "\033[0m"
def red_bold_underlined(string):
return bold + underlined + red + string + endc
x = red_bold_underlined('stackoverflow question')
print(x)
print(x.__repr__())
# pip install requests_html
from requests_html import HTMLSession
print()
print(x)
print(x.__repr__())
代码输出 https://i.stack.imgur.com/KMNh5.jpg
如果我评论该行:
from requests_html import HTMLSession
带有注释行的输出 https://i.stack.imgur.com/fjMtt.jpg
此外,在这些图像中,每个输出下都是字符串的表示版本,并且在每种情况下都是相同的,但问题是我不明白 requests_html 里面有什么,因为它在导入后取消了粗体和下划线效果。
我也尝试了其他模块,但这仅在我导入 requests_html 或从 requests_html 导入某些内容时才会发生。
我的问题是:我如何修复代码或问题以便在终端上输出粗体和下划线效果并在代码中导入 requests_html 模块?
解决方案
推荐阅读
- three.js - 在 Three.js (A-Frame) 中如何防止音频剪辑?
- html - Firefox 出现奇怪的 Favicon 问题
- redis - 如何使用 Istio 连接到集群外的 Redis?
- javascript - 有没有办法检测用户离开后何时返回您的网页?
- odoo - 在 one2many odoo 12 中获取默认值
- python - 如何动态定义`typing.Union`?
- jquery - Angular 7 - 数据表 - 上传按钮
- mongodb - 更新嵌套数组文档上的一个字段
- javascript - 如何在函数 JSDoc 中使用 @template 来创建参数和返回类型之间的一致性?
- python - python中运行平均值的简单程序产生超出范围的索引