如果您使用 python 写入文件,有什么方法可以使文本的某些部分变为粗体、斜体或下划线?
i tried:
test = '/location/tester.rtf'
out_file = open(test,'w')
out_file.write('is this {\bold}?')
out_file.close() #thanks to the comment below
是否可以通过 python 编写粗体、斜体或下划线文本等格式化文本?我觉得 .rtf 是最基本的格式化文本,但如果我错了,请纠正我
刚刚玩弄这个假设的 MS Word,我发现您需要将文档包装在“{}”中并定义文档类型,然后以“\b”粗体开始并以“\b0”结束。一个例子是
test = 'tester.rtf'
out_file = open(test,'w')
out_file.write("""{\\rtf1
This is \\b Bold \\b0\line\
}""")
out_file.close() #thanks to the comment below
请注意双“\”,因为 python 对“\b”和“\r”有特殊含义。
完整信息来自http://www.pindari.com/rtf1.html,还描述斜体、字体等。
让我知道这是否对你有用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)