[Tutor] stdout Question
Alan Gauld
alan.gauld at blueyonder.co.uk
Mon May 24 13:16:26 EDT 2004
> My OS is Win2000, and my Python version is 2.3.3 with the Win Addon
from
> Mark Hammond, whose IDE I use (PythonWin).
So far so good.
> What I simply want to do is print out a bold text/ or making the
first
> character in the text bold.
That depends entirely on where you print it.
Since your subject line says stdout I'll assume that's what you mean.
Stdout is a file, it is not a display device. Normally the stdout
file is redirected to a terminal screen, in your case a Command
Prompt (or DOS Box).
Basically the DOS BOx displays whatever the stdout file contains
so if you want to display Bold characters you need to insert
the ANSI control characters to enable/disable bold display.
ANSI control codes consist of the escape character followed
by a character, for example to clear the screen:
>>> # chr(27) is the ESC code, [2J is the clear screen combination
>>> print chr(27)+'[2J'
This used to be a common technique on PCs before Windows came along.
Its messy but works. Here is a web page with the various codes:
http://www.bluesock.org/~willg/dev/ansi.html
For it to work you will also need to ensure that ANSI.SYS is loaded
since it is ANSI.SYS that controls how DOS displays things,
it has nothing to do with Python.
In general if I want fancy formatting I opt to use a GUI like
Tkinter and its Text widget which allows me to do text
formatting more easily or if its for printouts I use HTML
and generate an intermediate file.
HTH,
Alan G.
More information about the Tutor
mailing list