os.write and file descriptor

Inyeol Lee inyeol.lee at siimage.com
Tue Feb 4 16:39:59 EST 2003


I'm writing a program which writes to file descriptor 3.
I've tried os.write() but it generates exception;

>>> import os
>>> os.write(3, "hello")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
OSError: [Errno 9] Bad file number

I've also tried equivalent C code, and it works fine;

#include <stdio.h>
#include <unistd.h>

int main(void)
{
    char s[] = "hello, world\n";
    write(3, s, strlen(s));
    return 0;
}

Is the usage of os.write() different from C? Am I missing something?

Thanks,
Inyeol Lee





More information about the Python-list mailing list