[Python-Dev] Windows IO

Martin v. L÷wis martin@v.loewis.de
17 Mar 2003 19:47:23 +0100

"David LeBlanc" <whisper@oz.net> writes:

> 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
> file_write(...)?
> 1. Is the above true, or does something different happen when using a
> Windows console/commandline?

If you ask "does writing occur in file_write, even on Windows", then
"yes".  If you ask "does all writing occur in file_write, even on
Windows", then "no". It also occurs in file_writelines, posix_write,
string_print, w_string, and many places that use fprintf (too many
to enumerate them here).

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

posix.isatty comes close.

> 3. What's the purpose of the PC/msvcrtmodule.c file? 

It exposes the following functions

	{"heapmin",		msvcrt_heapmin, METH_VARARGS},
	{"locking",             msvcrt_locking, METH_VARARGS},
	{"setmode",		msvcrt_setmode, METH_VARARGS},
	{"open_osfhandle",	msvcrt_open_osfhandle, METH_VARARGS},
	{"get_osfhandle",	msvcrt_get_osfhandle, METH_VARARGS},
	{"kbhit",		msvcrt_kbhit, METH_VARARGS},
	{"getch",		msvcrt_getch, METH_VARARGS},
	{"getche",		msvcrt_getche, METH_VARARGS},
	{"putch",		msvcrt_putch, METH_VARARGS},
	{"ungetch",		msvcrt_ungetch, METH_VARARGS},

as well as a few symbolic constants.

> Does it play any role in the regular pythonic IO scheme of things?

No. None of these functions is normally called; getpass.py uses