Can I write italics to the Python shell?

你说的曾经没有我的故事 提交于 2019-11-30 15:24:55

问题


Is it possible to write something like this:

>>> text_output = "Hello World."
>>> print text_output

...where if the text_output is printed to the Python Shell, it is printed in italics?


回答1:


If your console supports italics. Eg rxvt-unicode using ansi escape code

>>> print "\x1B[3mHello World\x1B[23m"




回答2:


Not in the standard Python shell, no. If you want all output text to be in italics, you could use some GUI shell like Dreampie. If you want the ability to actually style text (with italics, bold, etc.), you need to use some GUI library that provides that sort of ability.




回答3:


No. The print function outputs to sys.stdout by default. Assuming you're using something like IDLE, this will simply be echoed into IDLE. You can set some options in IDLE itself to show different font faces and sizes and whatnot, but this will modify everything, not just the output of print commands.



来源:https://stackoverflow.com/questions/13559276/can-i-write-italics-to-the-python-shell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!