[Python-Dev] RE: Windows IO
Mon, 17 Mar 2003 13:45:17 -0500
> It looks as though IO in Python (2.2.1), regardless of platform or device,
> happens in Objects/fileobject.c and, in particular, writing occurs in
For builtin file objects, at least there, and in file_writelines(), and it's
also possible to use f.fileno() and then use lower-level facilities (like
> A few questions I hope a lurking (timbot? ;) ) person can answer:
> 1. Is the above true, or does something different happen when using a
> Windows console/commandline?
Using one how? If via a Python file object, yes, the above is true.
> 2. Is there any way to know if a console is being used (that a
> device is the console)?
>>> import sys
>>> whatever = open('whatever.txt', 'w')
> 3. What's the purpose of the PC/msvcrtmodule.c file?
It implements the Windows-specific msvcrt module:
> Does it play any role in the regular pythonic IO scheme of things?
No, and mixing console-mode IO via that module with standard IO can be a
> 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. It would be nice if those could be used transparently to a
> python application so that an application sending (for instance)
> ANSI color codes would succede and one that didn't wouldn't care. I
> realize this is sort of like curses - is there a Windows version of curses
> that plays well with Python and isn't GPL?
This really belongw on c.l.py, where it gets asked frequently enough. I
haven't paid attention to the answers. Fredrik's Console extension for
Windows should tickle your fancy: