[Python-Dev] Windows IO

James C. Ahlstrom jim@interet.com
Mon, 17 Mar 2003 14:05:11 -0500

David LeBlanc wrote:

 >1. Is the above true, or does something different happen when using a
 >Windows console/commandline?

AFAIK, all Python IO uses the fprintf() functions of Windows.  These
stream IO functions are Posix emulations, are not the native
Windows IO functions, and are second class citizens.  The native
Windows IO functions are CreateFile(), ReadFile(), WriteFile() etc.
The native Windows functions support additional functionality.

 >2. Is there any way to know if a console is being used (that a device 
 >is the onsole)?

All Windows programs must provide a window to operate.  But
to make porting character-mode programs easier, Windows provides
a "Console Window" feature.  This is a Windows window you can
create which contains the handy features needed to support
character WriteFile() and fprintf().

Usually there is no need to test if a console is in use.  A
Windows program created as a console program has that coded
into its header, and the console is created when it starts.  It
is possible to use CreateProcess() to create a process and its
console window, but again there is no need to test.

 >3. What's the purpose of the PC/msvcrtmodule.c file? Does it play any 
 >in the regular pythonic IO scheme of things?

This is a handy module, but plays no role in Python IO.

 >I'm interested in discovering if the Win32 API for screen >reading/writing
 >can be used so that character color attributes and cursor
 >commands can be manipulated.

A console window supports arrays of cells, and the cell contains
the character and the cell attribule.  That means you can control
color of each cell.  Both character input and mouse input are
supported.  There is a cursor.  The whole thing is a lot like a
terminal (if anyone out there remembers those).

Jim Ahlstrom